airlift / airline

Java annotation-based framework for parsing Git like command line structures
Apache License 2.0
846 stars 138 forks source link

--help breaks when using required options when using singleCommand() #44

Open burtonator opened 9 years ago

burtonator commented 9 years ago

If I have:

@Option(name = { "--sourceIndexes"}, description = "Source indexes to read from.", required = true)
public List<String> sourceIndexes;

and then do --help it tells me:

io.airlift.airline.ParseOptionMissingException: Required option '--targetIndex' is missing

... but if I remove required=true

I'll get the proper help output.

which is not fun because for our use case this breaks airline. Though I might see if I can work around this.

ajs6f commented 7 years ago

I have the same problem. Perhaps it would be possible to have a notion of "required when X is not present"? That could actually be more valuable than just this use case.

ajs6f commented 7 years ago

Meanwhile, the pattern I am currently using is:

final SingleCommand<Tool> cliParser = singleCommand(MyCommand.class);
try {
    final Tool tool = cliParser.parse(args);
    tool.run();
} catch (ParseOptionMissingException e) {
    help(cliParser.getCommandMetadata());
    }
}

where help is com.github.rvesse.airline.help.Help.help(CommandMetadata).

findepi commented 6 years ago

This apparently duplicates https://github.com/airlift/airline/issues/22