Skip to content

Instantly share code, notes, and snippets.

@techthumb
Created August 7, 2020 17:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save techthumb/fe1e6be80bf65c4030e49b0c22d674bc to your computer and use it in GitHub Desktop.
Save techthumb/fe1e6be80bf65c4030e49b0c22d674bc to your computer and use it in GitHub Desktop.
picocli - runtime subcommand with options (no annotations)
import picocli.CommandLine;
import static picocli.CommandLine.*;
import static picocli.CommandLine.Model.*;
public class Demo {
public static void main(String[] args) {
CommandSpec rootSpec = CommandSpec.create();
final String commandName = "determined-at-runtime-from-remote-source";
rootSpec.addSubcommand(
commandName,
CommandSpec.wrapWithoutInspection(
new Runnable() {
@Override
public void run() {
System.out.println("How do I access value of 'runtime-option-a'?");
}
})
.addOption(OptionSpec.builder("runtime-option-a").build()));
System.exit(new CommandLine(rootSpec).setExecutionStrategy(new RunLast()).execute(commandName));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment