Skip to content

given 2 options, can the second option default value 'point' to the first option value? #2071

Answered by remkop
guykatz asked this question in Q&A
Discussion options

You must be logged in to vote

I haven't tried this, but one idea is to have a custom default provider, something like this:

@Command(defaultValueProvider = MyDefaultProvider.class)
class MyCommand {
  @Option(names = { "-in" }, description = "number of inputs. defaults to 1", defaultValue = "1")
  private int in;

  @Option(names = { "-out" }, description = "number of outputs. should default to inputChannelCount value")
  private int out;
}

class MyDefaultProvider implements IDefaultValueProvider {
    public String defaultValue(ArgSpec argSpec) {
        if (argSpec.isOption() && ((OptionSpec) argSpec).longestName().equals("-out")) {
            return argSpec.command().findOption("-in").getValue().toString();
     …

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@guykatz
Comment options

Answer selected by guykatz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants