Search in sources :

Example 1 with CommandLine

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();
}
Also used : CommandLine(picocli.CommandLine)

Example 2 with CommandLine

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;
}
Also used : CommandLine(picocli.CommandLine) CommandSpec(picocli.CommandLine.Model.CommandSpec) Main(org.keycloak.quarkus.runtime.cli.command.Main) PrintWriter(java.io.PrintWriter)

Example 3 with CommandLine

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));
}
Also used : OptionSpec(picocli.CommandLine.Model.OptionSpec) CommandLine(picocli.CommandLine) ParameterException(picocli.CommandLine.ParameterException)

Example 4 with CommandLine

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;
}
Also used : CommandLine(picocli.CommandLine)

Example 5 with CommandLine

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);
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) DiscoverySelectors.selectMethod(org.junit.platform.engine.discovery.DiscoverySelectors.selectMethod) Events(org.junit.platform.testkit.engine.Events) Enumeration(java.util.Enumeration) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Config(org.neo4j.configuration.Config) EventConditions.finishedSuccessfully(org.junit.platform.testkit.engine.EventConditions.finishedSuccessfully) StringUtils(org.apache.commons.lang3.StringUtils) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Map(java.util.Map) Mockito.doAnswer(org.mockito.Mockito.doAnswer) TestWatcher(org.junit.jupiter.api.extension.TestWatcher) TestDirectoryExtension(org.neo4j.test.extension.testdirectory.TestDirectoryExtension) Method(java.lang.reflect.Method) Path(java.nio.file.Path) CommandLine(picocli.CommandLine) AclFileAttributeView(java.nio.file.attribute.AclFileAttributeView) Set(java.util.Set) FileUtils(org.neo4j.io.fs.FileUtils) TestDirectory(org.neo4j.test.rule.TestDirectory) Test(org.junit.jupiter.api.Test) UncheckedIOException(java.io.UncheckedIOException) List(java.util.List) IS_OS_WINDOWS(org.apache.commons.lang3.SystemUtils.IS_OS_WINDOWS) Optional(java.util.Optional) BootloaderSettings(org.neo4j.configuration.BootloaderSettings) Mockito.mock(org.mockito.Mockito.mock) AclEntryPermission(java.nio.file.attribute.AclEntryPermission) ProcessUtil.start(org.neo4j.test.proc.ProcessUtil.start) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) ENGINE_ID(org.junit.jupiter.engine.descriptor.JupiterEngineDescriptor.ENGINE_ID) EventConditions.event(org.junit.platform.testkit.engine.EventConditions.event) ByteArrayOutputStream(java.io.ByteArrayOutputStream) GraphDatabaseSettings(org.neo4j.configuration.GraphDatabaseSettings) HashMap(java.util.HashMap) ExtensionContext(org.junit.jupiter.api.extension.ExtensionContext) Function(java.util.function.Function) PosixFilePermissions(java.nio.file.attribute.PosixFilePermissions) ResourceBundle(java.util.ResourceBundle) Inject(org.neo4j.test.extension.Inject) EngineTestKit(org.junit.platform.testkit.engine.EngineTestKit) PrintStream(java.io.PrintStream) Files(java.nio.file.Files) Setting(org.neo4j.graphdb.config.Setting) IOException(java.io.IOException) AclEntry(java.nio.file.attribute.AclEntry) OWNER_READ(java.nio.file.attribute.PosixFilePermission.OWNER_READ) AfterEach(org.junit.jupiter.api.AfterEach) AclEntryType(java.nio.file.attribute.AclEntryType) UNKNOWN_PID(org.neo4j.server.startup.BootloaderOsAbstraction.UNKNOWN_PID) OWNER_WRITE(java.nio.file.attribute.PosixFilePermission.OWNER_WRITE) Collections(java.util.Collections) PrintStream(java.io.PrintStream)

Aggregations

CommandLine (picocli.CommandLine)63 Test (org.junit.jupiter.api.Test)22 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)20 Copier (org.neo4j.pushtocloud.PushToCloudCommand.Copier)17 ParseResult (picocli.CommandLine.ParseResult)11 Path (java.nio.file.Path)9 Test (org.junit.Test)9 Parameters (junitparams.Parameters)8 CommandSpec (picocli.CommandLine.Model.CommandSpec)6 IOException (java.io.IOException)5 PrintWriter (java.io.PrintWriter)5 DumpCreator (org.neo4j.pushtocloud.PushToCloudCommand.DumpCreator)5 ParameterException (picocli.CommandLine.ParameterException)4 HashMap (java.util.HashMap)3 List (java.util.List)3 Set (java.util.Set)3 OptionSpec (picocli.CommandLine.Model.OptionSpec)3 File (java.io.File)2 PrintStream (java.io.PrintStream)2 Files (java.nio.file.Files)2