use of picocli.CommandLine in project TOSCAna by StuPro-TOSCAna.
the class CliMain method main.
public void main(String[] args) {
// Activate ANSI on Windows
AnsiConsole.systemInstall();
System.setProperty("picocli.ansi", "true");
// System Property gets set here, because picocli.trace must be set before CommandLine starts
String input = String.join("", args);
if (input.endsWith("-m")) {
System.setProperty("picocli.trace", "DEBUG");
} else if (input.endsWith("-v")) {
System.setProperty("picocli.trace", "INFO");
}
CommandLine commandLine = new CommandLine(new CliMain(), new CliPropertiesFactory(apiController));
commandLine.parseWithHandler(new CommandLine.RunLast(), System.err, args);
AnsiConsole.systemUninstall();
}
use of picocli.CommandLine in project keycloak by keycloak.
the class Picocli method createCommandLine.
public static CommandLine createCommandLine(List<String> cliArgs) {
CommandSpec spec = CommandSpec.forAnnotatedObject(new Main(), new DefaultFactory()).name(Environment.getCommand());
for (CommandLine subCommand : spec.subcommands().values()) {
CommandSpec subCommandSpec = subCommand.getCommandSpec();
// help option added to any subcommand
subCommandSpec.addOption(OptionSpec.builder(Help.OPTION_NAMES).usageHelp(true).description("This help message.").build());
}
addOption(spec, Start.NAME, hasAutoBuildOption(cliArgs), true);
addOption(spec, StartDev.NAME, true, true);
addOption(spec, Build.NAME, true, hasAutoBuildOption(cliArgs));
CommandLine cmd = new CommandLine(spec);
cmd.setExecutionExceptionHandler(new ExecutionExceptionHandler());
cmd.setParameterExceptionHandler(new ShortErrorMessageHandler());
cmd.setHelpFactory(new HelpFactory());
cmd.getHelpSectionMap().put(SECTION_KEY_COMMAND_LIST, new SubCommandListRenderer());
cmd.setErr(new PrintWriter(System.err, true));
return cmd;
}
use of picocli.CommandLine in project keycloak by keycloak.
the class PropertyMapperParameterConsumer method validateOption.
private void validateOption(Stack<String> args, ArgSpec argSpec, CommandSpec commandSpec) {
OptionSpec option = (OptionSpec) argSpec;
String name = String.join(", ", option.names());
CommandLine commandLine = commandSpec.commandLine();
if (args.isEmpty() || !isOptionValue(args.peek())) {
throw new ParameterException(commandLine, "Missing required value for option '" + name + "' (" + argSpec.paramLabel() + ")." + getExpectedValuesMessage(argSpec, option));
}
// consumes the value
String value = args.pop();
if (!args.isEmpty() && isOptionValue(args.peek())) {
throw new ParameterException(commandLine, "Option '" + name + "' expects a single value (" + argSpec.paramLabel() + ")" + getExpectedValuesMessage(argSpec, option));
}
if (isExpectedValue(option, value)) {
return;
}
throw new ParameterException(commandLine, "Invalid value for option '" + name + "': " + value + "." + getExpectedValuesMessage(argSpec, option));
}
use of picocli.CommandLine in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class VSCommandBase method getUsage.
@Override
public String getUsage(ICommandSender sender) {
if (usage == null) {
VSCommandFactory factory = new VSCommandFactory(sender);
CommandLine commandLine = new CommandLine(factory.create(cmdClass), factory);
usage = commandLine.getUsageMessage().replaceAll("^(Usage: )|\r", "");
}
return usage;
}
use of picocli.CommandLine in project neo4j by neo4j.
the class BootloaderCommandTestBase method createCommand.
private CommandLine createCommand(Map<String, String> environment) {
Function<String, String> envLookup = key -> {
if (environment.containsKey(key)) {
return environment.get(key);
}
return System.getenv(key);
};
Function<String, String> propLookup = key -> {
if (environment.containsKey(key)) {
return environment.get(key);
}
return System.getProperty(key);
};
return createCommand(new PrintStream(out), new PrintStream(err), envLookup, propLookup);
}
Aggregations