NAME
app a -
SYNOPSIS
app [(-n <number> | --number <number>)] a
OPTIONS
-n <number>, --number <number>
java -jar app-jar-with-dependencies.jar a --number 1
Exception in thread "main" io.airlift.airline.ParseArgumentsUnexpectedException: Found unexpected parameters: [--number, 1]
at io.airlift.airline.Cli.validate(Cli.java:148)
at io.airlift.airline.Cli.parse(Cli.java:116)
at io.airlift.airline.Cli.parse(Cli.java:97)
at my.App.main(App.java:23)```
Text book example:
public class App {
public static void main(String[] args) {
CliBuilder<Runnable> builder = new Cli.CliBuilder<Runnable>("app")
.withDescription("The app cli")
.withDefaultCommand(Help.class)
.withCommands(Help.class, A.class);
Cli<Runnable> parser = builder.build();
parser.parse(args).run();
}
public static abstract class Abstract implements Runnable {
@Option(name = {"-n", "--number"}, type = OptionType.GLOBAL)
public int number;
}
@Command(name = "a")
public static final class A extends Abstract {
@Override
public void run() {
System.out.println(number);
}
}
}
Hmm, the order matters.
Would be nice to document the difference between OptionType.GLOBAL and COMMAND because i actually wanted to the use the latter...
Problem solved.
java -jar app-jar-with-dependencies.jar help a
java -jar app-jar-with-dependencies.jar a --number 1
Text book example: