Created
August 7, 2020 17:06
-
-
Save techthumb/fe1e6be80bf65c4030e49b0c22d674bc to your computer and use it in GitHub Desktop.
picocli - runtime subcommand with options (no annotations)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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