-
Notifications
You must be signed in to change notification settings - Fork 0
Example
Christian Cwienk edited this page Oct 3, 2013
·
3 revisions
Consider the following CLI should be parsed:
mytool [--help --log <file>] [COMMAND]
COMMAND: clean|start
clean [-f|--force -d <directory>]
start [--return -d <workdir> -t <time>]
Then the corresponding declaration in Java might look like this:
class GlobalArgs
{
@HelpOption
boolean help; //help defaults to '--help'/'-h'
@Option(longOption="log")
File logFile;
@Command(name="clean")
CleanArgs clean;
@Command(name="start")
StartArgs start;
static class CleanArgs
{
@Option
boolean force; //options default to their field names
@Option(shortOption='d', converter=DirectoryThatExists.class)
File directory;
}
static class StartArgs
{
@Option(longOption="return")
boolean returnImmediatly;
@Option(shortOption='d', converter=DirectoryThatExists.class)
File directory;
@Option(shortOption='t', converter=IntegerValue.class)
int time;
}
}