Search in sources :

Example 16 with CommandLine

use of picocli.CommandLine in project neo4j by neo4j.

the class PushToCloudCommandTest method shouldAcceptOnlyUsernameAndPasswordFromCli.

@Test
public void shouldAcceptOnlyUsernameAndPasswordFromCli() throws IOException, CommandFailedException {
    // given
    Copier targetCommunicator = mockedTargetCommunicator();
    String username = "neo4j";
    String password = "abc";
    PushToCloudCommand command = command().copier(targetCommunicator).console(PushToCloudConsole.fakeConsole(username, password)).build();
    // when
    String[] args = { "--dump", dump.toString(), "--username", "neo4jcli", "--password", "passcli", "--bolt-uri", SOME_EXAMPLE_BOLT_URI };
    new CommandLine(command).execute(args);
    verify(targetCommunicator).authenticate(anyBoolean(), anyString(), eq("neo4jcli"), eq("passcli".toCharArray()), anyBoolean());
}
Also used : CommandLine(picocli.CommandLine) Copier(org.neo4j.pushtocloud.PushToCloudCommand.Copier) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 17 with CommandLine

use of picocli.CommandLine in project neo4j by neo4j.

the class PushToCloudCommandTest method shouldAcceptOnlyUsernameAndPasswordFromEnv.

@Test
public void shouldAcceptOnlyUsernameAndPasswordFromEnv() throws Exception {
    // given
    Copier targetCommunicator = mockedTargetCommunicator();
    String username = "neo4j";
    String password = "abc";
    PushToCloudCommand command = command().copier(targetCommunicator).console(PushToCloudConsole.fakeConsole(username, password)).build();
    // when
    String[] args = { "--dump", dump.toString(), "--bolt-uri", SOME_EXAMPLE_BOLT_URI };
    var environment = Map.of("NEO4J_USERNAME", "neo4jenv", "NEO4J_PASSWORD", "passenv");
    new CommandLine(command).setResourceBundle(new MapResourceBundle(environment)).execute(args);
    verify(targetCommunicator).authenticate(anyBoolean(), anyString(), eq("neo4jenv"), eq("passenv".toCharArray()), anyBoolean());
}
Also used : CommandLine(picocli.CommandLine) Copier(org.neo4j.pushtocloud.PushToCloudCommand.Copier) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 18 with CommandLine

use of picocli.CommandLine in project liquibase by liquibase.

the class LiquibaseCommandLine method buildPicoCommandLine.

private CommandLine buildPicoCommandLine() {
    final CommandLine.Model.CommandSpec rootCommandSpec = CommandLine.Model.CommandSpec.wrapWithoutInspection(null, defaultFactory);
    rootCommandSpec.name("liquibase");
    configureHelp(rootCommandSpec, true);
    rootCommandSpec.subcommandsCaseInsensitive(true);
    rootCommandSpec.usageMessage().customSynopsis("liquibase [GLOBAL OPTIONS] [COMMAND] [COMMAND OPTIONS]\nCommand-specific help: \"liquibase <command-name> --help\"").optionListHeading("\nGlobal Options\n").commandListHeading("\nCommands\n");
    CommandLine commandLine = new CommandLine(rootCommandSpec, defaultFactory).setCaseInsensitiveEnumValuesAllowed(true).setOptionsCaseInsensitive(true).setUsageHelpAutoWidth(true);
    addGlobalArguments(commandLine);
    for (CommandDefinition commandDefinition : getCommands()) {
        addSubcommand(commandDefinition, commandLine);
    }
    commandLine.setExecutionExceptionHandler((ex, commandLine1, parseResult) -> LiquibaseCommandLine.this.handleException(ex));
    return commandLine;
}
Also used : CommandLine(picocli.CommandLine)

Example 19 with CommandLine

use of picocli.CommandLine in project hazelcast by hazelcast.

the class HazelcastCommandLine method runCommandLine.

static void runCommandLine(Function<ClientConfig, HazelcastInstance> hzClientFn, PrintStream out, PrintStream err, boolean shouldExit, String[] args) {
    CommandLine cmd = new CommandLine(new HazelcastCommandLine(hzClientFn, out, err));
    cmd.getSubcommands().get("submit").setStopAtPositional(true);
    String version = getBuildInfo().getVersion();
    cmd.getCommandSpec().usageMessage().header("Hazelcast " + version);
    if (args.length == 0) {
        cmd.usage(out);
    } else {
        DefaultExceptionHandler<List<Object>> excHandler = new ExceptionHandler<List<Object>>().useErr(err).useAnsi(Ansi.AUTO);
        if (shouldExit) {
            excHandler.andExit(1);
        }
        List<Object> parsed = cmd.parseWithHandlers(new RunAll().useOut(out).useAnsi(Ansi.AUTO), excHandler, args);
        // only top command was executed
        if (parsed != null && parsed.size() == 1) {
            cmd.usage(out);
        }
    }
}
Also used : DefaultExceptionHandler(picocli.CommandLine.DefaultExceptionHandler) CommandLine(picocli.CommandLine) RunAll(picocli.CommandLine.RunAll) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) Util.idToString(com.hazelcast.jet.Util.idToString)

Example 20 with CommandLine

use of picocli.CommandLine in project hazelcast by hazelcast.

the class HazelcastServerCommandLine method runCommandLine.

private static void runCommandLine(String[] args) {
    PrintStream out = System.out;
    PrintStream err = System.err;
    CommandLine cmd = new CommandLine(new HazelcastServerCommandLine()).setOut(createPrintWriter(out)).setErr(createPrintWriter(err)).setTrimQuotes(true).setExecutionExceptionHandler(new ExceptionHandler());
    cmd.execute(args);
    String version = getBuildInfo().getVersion();
    cmd.getCommandSpec().usageMessage().header("Hazelcast " + version);
    if (args.length == 0) {
        cmd.usage(out);
    }
}
Also used : PrintStream(java.io.PrintStream) CommandLine(picocli.CommandLine)

Aggregations

CommandLine (picocli.CommandLine)45 Test (org.junit.jupiter.api.Test)22 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)19 Copier (org.neo4j.pushtocloud.PushToCloudCommand.Copier)17 Path (java.nio.file.Path)9 DumpCreator (org.neo4j.pushtocloud.PushToCloudCommand.DumpCreator)5 ParseResult (picocli.CommandLine.ParseResult)5 IOException (java.io.IOException)4 PrintWriter (java.io.PrintWriter)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Set (java.util.Set)3 ParameterException (picocli.CommandLine.ParameterException)3 PrintStream (java.io.PrintStream)2 Files (java.nio.file.Files)2 Map (java.util.Map)2 ServiceProvider (com.b2international.snowowl.core.ServiceProvider)1 AuthorizedEventBus (com.b2international.snowowl.core.authorization.AuthorizedEventBus)1 JWTGenerator (com.b2international.snowowl.core.identity.JWTGenerator)1 Environment (com.b2international.snowowl.core.setup.Environment)1