question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support repeating composite arguments (was: Parameter options/modifiers)

See original GitHub issue

Picocli supports mixing options and parameters: http://picocli.info/#_mixing_options_and_positional_parameters

I would like to know what options have been specified before certain parameter. Consider such command:

print --paper A4 A.pdf --count 3 B.pdf --rotate left C.pdf -- D.pdf --rotate right E.pdf

Where:

  • --paper is an global option,
  • --count and --rotate are “local” options, or parameter modifiers,
  • -- reset local options.

So, that command would evaluate to:

  • globals: paper = A4,
  • parameter A.pdf: count = default, rotate = default,
  • parameter B.pdf: count = 3, rotate = default,
  • parameter C.pdf: count = 3, rotate = left,
  • parameter D.pdf: count = default, rotate = default,
  • parameter E.pdf: count = default, rotate = right.

Is there support for such things in picocli?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
remkopcommented, Mar 30, 2019

Picocli 4.0.0-alpha-1 has been released which includes support for repeating composite groups. See https://picocli.info/#_argument_groups for details.

Please try this and provide feedback. We can still make changes.

What do you think of the annotations API? What about the programmatic API? Does it work as expected? Are the input validation error messages correct and clear? Is the documentation clear and complete? Anything you want to change or improve? Any other feedback?

0reactions
bbottemacommented, Aug 25, 2018
--email:from name=String fromAddress=STRING

That’s the synopsis, but the invocation currently is:

--email:from "some string" "some address string"

In case it keeps working like this, then the answer to your question depends on the implementation of how arguments are referenced after parsing:

If these composite option values would have to be predefined (ie. a class with declared fields), then it would be useful and feasible to have optional fields (being referable by name). However, in my use case I prefer to leave to the composition unbounded (ie. an array of arbitrary number of types of mandatory parameter values). This is because I’m generating the composite signatures in runtime using reflection.

To illustrate, I prefer:

{ String.class, Integer.class, Boolean.class }

over:

class CompositeOptionValue {
   String a;
   Integer b;
   Boolean c;
}

Of course, you could work with a Map here:

"a" : String.class,
"b" : Integer.class,
"c" : Boolean.class

In this case the parsed arguments can be referenced by name but also generated by name in run time, in which case optional values are workable again. Without named arguments, it will become impossible to know which parameters of a java Method should be null.

In general though, I have to add that I don’t have many optional parameters, because that would imply that there is a different need than the API provides and I would simply add an overloaded more succinct version with that parameter left out.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Repeating options with sub-options/arguments #635 - GitHub
I would like to add an option multiple times and add sub-options/parameters to it. In my scenario, I have a viewer application and, ......
Read more >
CommandLine.ArgGroup (picocli 4.7.0 API)
By default, options and positional parameters in a group are mutually exclusive. ... the usage help message. define composite repeating argument groups.
Read more >
Search - FHIR v5.0.0-cibuild
Search parameter definitions MAY include a list of allowed modifiers in the SearchParameter.code element, which is bound to the search-modifier-code value set.
Read more >
Contracts — Solidity 0.8.17 documentation
Modifiers are inheritable properties of contracts and may be overridden by derived contracts, but only if they are marked virtual . For details,...
Read more >
Compose modifiers - Jetpack - Android Developers
Jetpack Compose provides a list of built-in modifiers to help you decorate or augment a composable. Here are some common modifiers you'll use...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found