Example usage for org.apache.commons.cli BasicParser BasicParser

List of usage examples for org.apache.commons.cli BasicParser BasicParser

Introduction

In this page you can find the example usage for org.apache.commons.cli BasicParser BasicParser.

Prototype

BasicParser

Source Link

Usage

From source file:com.toy.TOYConfig.java

public static final TOYConfig parse(String[] args) {
    CommandLineParser parser = new BasicParser();
    CommandLine commandLine = null;//  w  w w. j  a  va2  s.  c o m
    Command command = null;
    try {
        commandLine = parser.parse(get(), args);
    } catch (ParseException e) {
        LOG.error("\n{}", e.getLocalizedMessage());
        LOG.debug("Can't parse cmd line", e);
    }
    if (commandLine == null) {
        printHelp();
        System.exit(-1);
    }

    // start, stop or status ?
    boolean start = commandLine.hasOption("start");
    boolean stop = commandLine.hasOption("stop");
    boolean status = commandLine.hasOption("status");
    boolean add = commandLine.hasOption("add");

    if (start && stop || stop && status) {
        printHelp();
        System.exit(-1);
    }
    if (add)
        command = Command.ADD;
    if (start)
        command = Command.START;
    if (stop)
        command = Command.STOP;
    if (status)
        command = Command.STATUS;

    if (command == Command.ADD || command == Command.START)
        Preconditions.checkNotNull(commandLine.getOptionValue("war"), "Please specify application with -war");

    return new TOYConfig(commandLine.getOptionValue("zookeeper"), commandLine.getOptionValue("tomcat"),
            commandLine.getOptionValue("war"), commandLine.getOptionValue("queue", "default"),
            commandLine.getOptionValue("memory", "64"), commandLine.getOptionValue("ns", "default"), command);

}

From source file:net.oebs.jalos.JalosMain.java

private static Settings createSettings(String[] args) throws SettingsError {
    Options options = new Options();
    options.addOption("c", "config", true, "config file path");

    CommandLineParser parser = new BasicParser();
    try {/*from   w w w  .  j  ava  2 s .  com*/
        CommandLine cmd = parser.parse(options, args);
    } catch (ParseException e) {
        // TODO
    }

    String configFile = options.getOption("c").getValue("jalos.properties");
    Settings settings = null;

    try {
        settings = new Settings(configFile);
    } catch (FileNotFoundException e) {
        // TODO
    }
    return settings;
}

From source file:com.predic8.membrane.core.MembraneCommandLine.java

public void parse(String[] args) throws ParseException {
    cl = new BasicParser().parse(getOptions(), args, true);
}

From source file:jetbrains.exodus.console.Console.java

private static CommandLine getCommandLine(String[] args) throws ParseException {
    Options options = new Options();
    options.addOption(OptionBuilder.hasArg().withType(Number.class).withDescription("sshd port").create('l'));
    options.addOption(OptionBuilder.hasArg().withDescription("password to login").create('p'));
    options.addOption(OptionBuilder.hasArg().withDescription("xodus database path").create('x'));

    if (args.length <= 0) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(Console.class.getCanonicalName(), options);
    }//from w  w  w.j  a va  2s  . c o  m

    // create the parser
    CommandLineParser parser = new BasicParser();
    return parser.parse(options, args);
}

From source file:com.siemens.sw360.UtilsEntryPoint.java

private static CommandLine parseArgs(String[] args) throws ParseException {
    Options options = getOptions();//  w  ww  .j  av a  2s .  co  m

    return new BasicParser().parse(options, args, true);
}

From source file:ezbake.services.search.SSRServer.java

private static CommandLine parseCommandLine(String[] args) {
    CommandLineParser parser = new BasicParser();
    Options options = new Options();
    options.addOption(buildOption("Application Name", 'a'));
    options.addOption(buildOption("Thrift server listen port", 'l'));
    options.addOption(buildOption("Zookeeper string (host:port)", 'z'));
    try {/*from   w w w  .j a  v  a2  s  . c o  m*/
        return parser.parse(options, args);
    } catch (ParseException e) {
        System.out.println(e.getMessage());
        new HelpFormatter().printHelp("ezbake.services.search.SSRServer", options, true);
        System.exit(0);
        return null;
    }
}

From source file:eagle.dataproc.util.ConfigOptionParser.java

@Override
protected Parser parser() {
    return new BasicParser();
}

From source file:ArgumentHandler.java

public CommandLine parse(String[] args) {
    CommandLine commandLine;/*from   w  w  w .  ja va 2  s.  c om*/
    try {
        CommandLineParser parser = new BasicParser();
        commandLine = parser.parse(options, args);
        return commandLine;
    } catch (Exception e) {
        usage("\nImproper Usage!\n");
        System.exit(1);
        return null;
    }
}

From source file:guru.nidi.ramlproxy.cli.ClientOptionsParser.java

@Override
protected ClientOptions parse(String[] args) throws ParseException {
    final CommandLine cmd = new BasicParser().parse(createOptions(), expandArgs(args));

    final int port = parsePort(cmd);
    final Command command = parseCommand(cmd);
    final boolean clearReports = cmd.hasOption('r');
    final boolean clearUsage = cmd.hasOption('u');
    return new ClientOptions(command, port, clearReports, clearUsage);
}

From source file:hws.core.JobMaster.java

public static void main(String[] args) throws Exception {
    Options options = new Options();
    options.addOption(OptionBuilder.withLongOpt("app-id").withDescription("String of the Application Id ")
            .hasArg().withArgName("AppId").create("aid"));
    options.addOption(OptionBuilder.withLongOpt("load").withDescription("load module pipeline").hasArg()
            .withArgName("Json-Base64").create());
    options.addOption(OptionBuilder.withLongOpt("remove").withDescription("remove modules").hasArgs()
            .withArgName("ModuleNames").create("rm"));
    options.addOption(OptionBuilder.withLongOpt("zk-servers").withDescription("List of the ZooKeeper servers")
            .hasArgs().withArgName("zkAddrs").create("zks"));
    CommandLineParser parser = new BasicParser();
    CommandLine cmd = parser.parse(options, args);

    String appIdStr = null;//from  w  w  w .ja  v  a 2 s. co  m
    String modulePipelineBase64 = null;
    String modulePipelineJson = null;
    ModulePipeline modulePipeline = null;
    String[] moduleNames = null;
    if (cmd.hasOption("aid")) {
        appIdStr = cmd.getOptionValue("aid");
    }
    String zksArgs = "";
    String[] zkServers = null;
    if (cmd.hasOption("zks")) {
        zksArgs = "-zks";
        zkServers = cmd.getOptionValues("zks");
        for (String zks : zkServers) {
            zksArgs += " " + zks;
        }
    }
    if (cmd.hasOption("load")) {
        modulePipelineBase64 = cmd.getOptionValue("load");
        modulePipelineJson = StringUtils.newStringUtf8(Base64.decodeBase64(modulePipelineBase64));
        modulePipeline = Json.loads(modulePipelineJson, ModulePipeline.class);
    } else if (cmd.hasOption("rm")) {
        moduleNames = cmd.getOptionValues("rm");
    }

    JobMaster master = new JobMaster(modulePipeline, appIdStr, zksArgs, zkServers);

    if (modulePipelineJson != null) {
        Logger.info("Module Pipeline: " + modulePipelineJson);
        Logger.info("Instances: " + Json.dumps(modulePipeline.instances()));
    }
    master.runMainLoop();
}