Search in sources :

Example 36 with JCommander

use of com.beust.jcommander.JCommander in project GeoGig by boundlessgeo.

the class SLCommandProxy method getCommandParser.

/**
     * @return the JCommander parser for this extension
     * @see JCommander
     */
@Override
public JCommander getCommandParser() {
    JCommander commander = new JCommander();
    commander.setProgramName("geogig sl");
    commander.addCommand("import", new SLImport());
    commander.addCommand("list", new SLList());
    commander.addCommand("describe", new SLDescribe());
    commander.addCommand("export", new SLExport());
    return commander;
}
Also used : SLList(org.locationtech.geogig.geotools.cli.porcelain.SLList) SLExport(org.locationtech.geogig.geotools.cli.porcelain.SLExport) JCommander(com.beust.jcommander.JCommander) SLImport(org.locationtech.geogig.geotools.cli.porcelain.SLImport) SLDescribe(org.locationtech.geogig.geotools.cli.porcelain.SLDescribe)

Example 37 with JCommander

use of com.beust.jcommander.JCommander in project jvm-tools by aragozin.

the class CommandLauncher method start.

public boolean start(String[] args) {
    JCommander parser = null;
    try {
        parser = new JCommander(this);
        addCommands(parser);
        try {
            parser.parse(args);
        } catch (Exception e) {
            failAndPrintUsage(e.toString());
        }
        if (help) {
            String cmd = parser.getParsedCommand();
            if (cmd == null) {
                parser.usage();
            } else {
                parser.usage(cmd);
            }
        } else if (listCommands) {
            for (String cmd : commands.keySet()) {
                System.out.println(String.format("%8s - %s", cmd, parser.getCommandDescription(cmd)));
            }
        } else {
            Runnable cmd = commands.get(parser.getParsedCommand());
            if (cmd == null) {
                failAndPrintUsage();
            } else {
                cmd.run();
            }
        }
        if (suppressSystemExit) {
            return true;
        } else {
            System.exit(0);
        }
    } catch (CommandAbortedError error) {
        for (String m : error.messages) {
            logError(m);
        }
        if (verbose && error.getCause() != null) {
            logTrace(error.getCause());
        }
        if (error.printUsage && parser != null) {
            if (parser.getParsedCommand() != null) {
                parser.usage(parser.getParsedCommand());
            } else {
                parser.usage();
            }
        }
    } catch (Throwable e) {
        e.printStackTrace();
    }
    // abnormal termination
    if (suppressSystemExit) {
        return false;
    } else {
        System.exit(1);
        return false;
    }
}
Also used : JCommander(com.beust.jcommander.JCommander) IOException(java.io.IOException)

Example 38 with JCommander

use of com.beust.jcommander.JCommander in project jvm-tools by aragozin.

the class YoungGCStarter method main.

public static void main(String[] args) throws IOException {
    JCommander jcmd = new JCommander();
    YoungGCPauseBenchmark bench = new YoungGCPauseBenchmark();
    jcmd.addCommand("ygc", bench);
    jcmd.parse(args);
    String cmd = jcmd.getParsedCommand();
    if (cmd != null) {
        bench.benchmark();
    } else {
        jcmd.usage();
    }
}
Also used : JCommander(com.beust.jcommander.JCommander)

Example 39 with JCommander

use of com.beust.jcommander.JCommander in project disunity by ata4.

the class Command method addSubCommand.

protected JCommander addSubCommand(String commandName, Command commandObj) {
    commander.addCommand(commandName, commandObj);
    JCommander subCommander = commander.getCommands().get(commandName);
    commandObj.init(subCommander, out);
    return subCommander;
}
Also used : JCommander(com.beust.jcommander.JCommander)

Example 40 with JCommander

use of com.beust.jcommander.JCommander in project disunity by ata4.

the class Command method run.

@Override
public void run() {
    String commandName = commander.getParsedCommand();
    if (!commander.getCommands().isEmpty()) {
        JCommander command = commander.getCommands().get(commandName);
        if (command != null && !command.getObjects().isEmpty()) {
            Command commandObj = (Command) command.getObjects().get(0);
            commandObj.run();
        } else {
            // no command selected, show usage
            usage();
        }
    }
}
Also used : JCommander(com.beust.jcommander.JCommander)

Aggregations

JCommander (com.beust.jcommander.JCommander)65 ParameterException (com.beust.jcommander.ParameterException)15 IOException (java.io.IOException)10 Map (java.util.Map)6 ParameterDescription (com.beust.jcommander.ParameterDescription)4 FileInputStream (java.io.FileInputStream)3 Console (com.beust.jcommander.internal.Console)2 DefaultCommand (com.evolveum.midpoint.cli.common.DefaultCommand)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Charsets (com.google.common.base.Charsets)2 Throwables (com.google.common.base.Throwables)2 HostAndPort (com.google.common.net.HostAndPort)2 Service (com.google.common.util.concurrent.Service)2 CreationException (com.google.inject.CreationException)2 SystemException (com.torodb.core.exceptions.SystemException)2 BackendPasswordConfig (com.torodb.packaging.config.model.backend.BackendPasswordConfig)2 AbstractDerby (com.torodb.packaging.config.model.backend.derby.AbstractDerby)2 AbstractPostgres (com.torodb.packaging.config.model.backend.postgres.AbstractPostgres)2 AbstractReplication (com.torodb.packaging.config.model.protocol.mongo.AbstractReplication)2 MongoPasswordConfig (com.torodb.packaging.config.model.protocol.mongo.MongoPasswordConfig)2