Search in sources :

Example 41 with CommandLine

use of picocli.CommandLine in project neo4j by neo4j.

the class PushToCloudCommandTest method shouldAcceptDumpAsSource.

@Test
void shouldAcceptDumpAsSource() throws Exception {
    // given
    Copier targetCommunicator = mockedTargetCommunicator();
    PushToCloudCommand command = command().copier(targetCommunicator).build();
    // when
    PushToCloudCommand.Uploader uploader = command.makeDumpUploader(this.dump);
    String[] args = { "--dump", dump.toString(), "--bolt-uri", SOME_EXAMPLE_BOLT_URI };
    new CommandLine(command).execute(args);
    // then
    verify(targetCommunicator).checkSize(anyBoolean(), any(), anyLong(), any());
    verify(targetCommunicator).copy(anyBoolean(), any(), any(), eq(uploader.source), eq(false), any());
}
Also used : CommandLine(picocli.CommandLine) Copier(org.neo4j.pushtocloud.PushToCloudCommand.Copier) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 42 with CommandLine

use of picocli.CommandLine in project neo4j by neo4j.

the class PushToCloudCommandTest method shouldUseNeo4jAsDefaultUsernameIfUserHitsEnter.

@Test
public void shouldUseNeo4jAsDefaultUsernameIfUserHitsEnter() throws Exception {
    // given
    Copier targetCommunicator = mockedTargetCommunicator();
    PushToCloudConsole console = mock(PushToCloudConsole.class);
    when(console.readLine(anyString(), anyString())).thenReturn("");
    String defaultUsername = "neo4j";
    String password = "super-secret-password";
    PushToCloudCommand command = command().copier(targetCommunicator).console(console).build();
    // when
    String[] args = { "--dump", dump.toString(), "--bolt-uri", SOME_EXAMPLE_BOLT_URI, "--password", password.toString() };
    new CommandLine(command).execute(args);
    // then
    verify(console).readLine("%s", format("Neo4j aura username (default: %s):", defaultUsername));
    verify(targetCommunicator).authenticate(anyBoolean(), any(), eq(defaultUsername), eq(password.toCharArray()), anyBoolean());
    verify(targetCommunicator).copy(anyBoolean(), any(), any(), any(), eq(false), any());
}
Also used : CommandLine(picocli.CommandLine) Copier(org.neo4j.pushtocloud.PushToCloudCommand.Copier) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 43 with CommandLine

use of picocli.CommandLine in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class VSCommandBase method execute.

@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) {
    VSCommandFactory factory = new VSCommandFactory(sender);
    CommandLine commandLine = new CommandLine(factory.create(cmdClass), factory);
    registerConverters(commandLine, sender);
    ChatWriter chatOut = new ChatWriter(sender);
    commandLine.setOut(chatOut);
    commandLine.setErr(chatOut);
    args = VSCommandUtil.toProperArgs(args);
    commandLine.execute(args);
}
Also used : CommandLine(picocli.CommandLine)

Example 44 with CommandLine

use of picocli.CommandLine in project groovy by apache.

the class FileSystemCompiler method commandLineCompile.

/**
 * Same as main(args) except that exceptions are thrown out instead of causing
 * the VM to exit and the lookup for .groovy files can be controlled
 */
public static void commandLineCompile(String[] args, boolean lookupUnnamedFiles) throws Exception {
    CompilationOptions options = new CompilationOptions();
    CommandLine parser = configureParser(options);
    ParseResult parseResult = parser.parseArgs(args);
    if (CommandLine.printHelpIfRequested(parseResult)) {
        return;
    }
    displayStackTraceOnError = options.printStack;
    CompilerConfiguration configuration = options.toCompilerConfiguration();
    // Load the file name list
    String[] filenames = options.generateFileNames();
    boolean fileNameErrors = filenames == null;
    if (!fileNameErrors && (filenames.length == 0)) {
        parser.usage(System.err);
        return;
    }
    fileNameErrors = fileNameErrors && !validateFiles(filenames);
    if (!fileNameErrors) {
        doCompilation(configuration, null, filenames, lookupUnnamedFiles);
    }
}
Also used : CommandLine(picocli.CommandLine) ParseResult(picocli.CommandLine.ParseResult) CompilerConfiguration(org.codehaus.groovy.control.CompilerConfiguration)

Example 45 with CommandLine

use of picocli.CommandLine in project jgnash by ccavanaugh.

the class jGnashFx method main.

public static void main(final String[] args) {
    if (OS.getJavaVersion() < 11f) {
        System.err.println(ResourceUtils.getString("Message.JVM11"));
        System.err.println(ResourceUtils.getString("Message.Version") + " " + System.getProperty("java.version") + "\n");
        // show a swing based dialog
        JOptionPane.showMessageDialog(null, ResourceUtils.getString("Message.JVM11"), ResourceUtils.getString("Title.Error"), JOptionPane.ERROR_MESSAGE);
        return;
    }
    // Register the default exception handler
    Thread.setDefaultUncaughtExceptionHandler(new StaticUIMethods.ExceptionHandler());
    final CommandLine commandLine = new CommandLine(new CommandLineOptions());
    commandLine.setToggleBooleanFlags(false);
    commandLine.setUsageHelpWidth(80);
    try {
        final ParseResult pr = commandLine.parseArgs(args);
        final CommandLineOptions options = commandLine.getCommand();
        if (CommandLine.printHelpIfRequested(pr)) {
            System.exit(0);
        }
        // check for bad server file and hostName combination... can't do both
        if (serverFile != null && options.hostName != null) {
            commandLine.usage(System.err, Help.Ansi.AUTO);
            System.exit(1);
        }
        configureLogging();
        if (options.uninstall) {
            PortablePreferences.deleteUserPreferences();
            System.exit(0);
        }
        // System.getProperties().put(EncryptionManager.ENCRYPTION_FLAG, Boolean.toString(options.ssl));
        // System.getProperties().put("ssl", Boolean.toString(options.ssl));
        port = options.port;
        hostName = options.hostName;
        password = options.password;
        if (options.shutdown) {
            if (hostName == null) {
                hostName = EngineFactory.LOCALHOST;
            }
            MessageBus.getInstance().shutDownRemoteServer(hostName, port + 1, password);
            System.exit(0);
        }
        if (options.verbose) {
            System.setProperty("javafx.verbose", "true");
        }
        if (options.portableFile != null) {
            PortablePreferences.initPortablePreferences(options.portableFile.getAbsolutePath());
        } else if (options.portable) {
            PortablePreferences.initPortablePreferences(null);
        }
        if (options.zeroArgFile != null && options.zeroArgFile.exists()) {
            jGnashFx.dataFile = options.zeroArgFile;
        }
        if (options.dataFile != null && options.dataFile.exists()) {
            jGnashFx.dataFile = options.dataFile;
        }
        if (options.serverFile != null && options.serverFile.exists()) {
            jGnashFx.serverFile = options.serverFile;
            startServer();
        } else {
            setupNetworking();
            launch(args);
        }
    } catch (final Exception e) {
        logSevere(jGnashFx.class, e);
        commandLine.usage(System.err, Help.Ansi.AUTO);
        System.exit(1);
    }
}
Also used : CommandLine(picocli.CommandLine) ParseResult(picocli.CommandLine.ParseResult) StaticUIMethods(jgnash.uifx.StaticUIMethods) FileNotFoundException(java.io.FileNotFoundException)

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