Example usage for org.apache.commons.cli OptionBuilder withArgName

List of usage examples for org.apache.commons.cli OptionBuilder withArgName

Introduction

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

Prototype

public static OptionBuilder withArgName(String name) 

Source Link

Document

The next Option created will have the specified argument value name.

Usage

From source file:mitm.application.djigzo.tools.ProxyManager.java

@SuppressWarnings("static-access")
private Options createCommandLineOptions() {
    Options options = new Options();

    Option getOption = OptionBuilder.create("get");
    getOption.setRequired(false);/* ww w  .  j a va 2s. c o  m*/
    getOption.setDescription("Returns the proxy settings");
    options.addOption(getOption);

    Option userOption = OptionBuilder.withArgName("user").hasArg().withDescription("user").create("user");
    userOption.setRequired(false);
    options.addOption(userOption);

    Option passwordOption = OptionBuilder.withArgName("password").hasArg().withDescription("password")
            .create("password");
    passwordOption.setRequired(false);
    options.addOption(passwordOption);

    Option passwordPromptOption = OptionBuilder.withDescription("ask for password").create("pwd");
    passwordPromptOption.setRequired(false);
    options.addOption(passwordPromptOption);

    Option helpOption = OptionBuilder.withDescription("Show help").create("help");
    helpOption.setRequired(false);
    options.addOption(helpOption);

    hostOption = OptionBuilder.withArgName("host").hasArg()
            .withDescription("The host to connect to (127.0.0.1)").create("host");
    options.addOption(hostOption);

    portOption = OptionBuilder.withArgName("port").hasArg()
            .withDescription("The port to use (" + DjigzoWSDefaults.PORT + ")").create("port");
    options.addOption(portOption);

    return options;
}

From source file:cc.twittertools.download.AsyncEmbeddedJsonStatusBlockCrawler.java

@SuppressWarnings("static-access")
public static void main(String[] args) throws Exception {
    Options options = new Options();
    options.addOption(OptionBuilder.withArgName("path").hasArg().withDescription("data file with tweet ids")
            .create(DATA_OPTION));//from w  w  w.j  a v  a2 s  . c  o m
    options.addOption(OptionBuilder.withArgName("path").hasArg().withDescription("output file (*.gz)")
            .create(OUTPUT_OPTION));
    options.addOption(OptionBuilder.withArgName("path").hasArg()
            .withDescription("output repair file (can be used later as a data file)").create(REPAIR_OPTION));
    options.addOption(NOFOLLOW_OPTION, NOFOLLOW_OPTION, false, "don't follow 301 redirects");

    CommandLine cmdline = null;
    CommandLineParser parser = new GnuParser();
    try {
        cmdline = parser.parse(options, args);
    } catch (ParseException exp) {
        System.err.println("Error parsing command line: " + exp.getMessage());
        System.exit(-1);
    }

    if (!cmdline.hasOption(DATA_OPTION) || !cmdline.hasOption(OUTPUT_OPTION)) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(AsyncEmbeddedJsonStatusBlockCrawler.class.getName(), options);
        System.exit(-1);
    }

    String data = cmdline.getOptionValue(DATA_OPTION);
    String output = cmdline.getOptionValue(OUTPUT_OPTION);
    String repair = cmdline.getOptionValue(REPAIR_OPTION);
    boolean noFollow = cmdline.hasOption(NOFOLLOW_OPTION);
    new AsyncEmbeddedJsonStatusBlockCrawler(new File(data), output, repair, noFollow).fetch();
}

From source file:chibi.gemmaanalysis.OutlierDetectionTestCli.java

@Override
@SuppressWarnings("static-access")
protected void buildOptions() {
    super.buildOptions();
    Option outputFileOption = OptionBuilder.hasArg().withArgName("filename")
            .withDescription("Name and path of output file.").withLongOpt("output").create('o');

    addOption(outputFileOption);//from w  w w  .j  a v  a 2  s.  c o  m

    Option regressionOption = OptionBuilder.withArgName("regression")
            .withDescription("Regress out significant experimental factors before detecting outliers.")
            .withLongOpt("regression").create('r');

    addOption(regressionOption);

    Option findByMedianOption = OptionBuilder.withArgName("findByMedian")
            .withDescription(
                    "Find outliers by comparing first, second, or third quartiles of sample correlations.")
            .withLongOpt("findByMedian").create('m');

    addOption(findByMedianOption);

    Option combinedMethodOption = OptionBuilder.withArgName("combinedMethod")
            .withDescription("Combine results from two outlier detection methods.").withLongOpt("combined")
            .create('c');

    addOption(combinedMethodOption);
}

From source file:com.google.code.linkedinapi.client.examples.MessagingApiExample.java

/**
  * Build command line options object./* w ww. j a  va2 s  . c  o m*/
  */
private static Options buildOptions() {

    Options opts = new Options();

    String helpMsg = "Print this message.";
    Option help = new Option(HELP_OPTION, helpMsg);
    opts.addOption(help);

    String consumerKeyMsg = "You API Consumer Key.";
    OptionBuilder.withArgName("consumerKey");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(consumerKeyMsg);
    Option consumerKey = OptionBuilder.create(CONSUMER_KEY_OPTION);
    opts.addOption(consumerKey);

    String consumerSecretMsg = "You API Consumer Secret.";
    OptionBuilder.withArgName("consumerSecret");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(consumerSecretMsg);
    Option consumerSecret = OptionBuilder.create(CONSUMER_SECRET_OPTION);
    opts.addOption(consumerSecret);

    String accessTokenMsg = "You OAuth Access Token.";
    OptionBuilder.withArgName("accessToken");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(accessTokenMsg);
    Option accessToken = OptionBuilder.create(ACCESS_TOKEN_OPTION);
    opts.addOption(accessToken);

    String tokenSecretMsg = "You OAuth Access Token Secret.";
    OptionBuilder.withArgName("accessTokenSecret");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(tokenSecretMsg);
    Option accessTokenSecret = OptionBuilder.create(ACCESS_TOKEN_SECRET_OPTION);
    opts.addOption(accessTokenSecret);

    String idMsg = "IDs of the users to whom a message is to be sent (separated by comma).";
    OptionBuilder.withArgName("ids");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(idMsg);
    Option id = OptionBuilder.create(ID_OPTION);
    opts.addOption(id);

    String subjectMsg = "Subject of the message.";
    OptionBuilder.withArgName("subject");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(subjectMsg);
    Option subject = OptionBuilder.create(SUBJECT_OPTION);
    opts.addOption(subject);

    String messageMsg = "Content of the message.";
    OptionBuilder.withArgName("message");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(messageMsg);
    Option message = OptionBuilder.create(MESSAGE_OPTION);
    opts.addOption(message);

    return opts;
}

From source file:cn.edu.pku.cbi.mosaichunter.MosaicHunter.java

private static boolean loadConfiguration(String[] args, String configFile) throws Exception {
    OptionBuilder.withArgName("file");
    OptionBuilder.hasArg();// w  w  w .j a va 2s. c o  m
    OptionBuilder.withDescription("config file");
    OptionBuilder.withLongOpt("config");
    Option configFileOption = OptionBuilder.create("C");

    OptionBuilder.withArgName("property=value");
    OptionBuilder.hasArgs(2);
    OptionBuilder.withValueSeparator();
    OptionBuilder.withDescription("properties that overrides the ones in config file");
    OptionBuilder.withLongOpt("properties");
    Option propertiesOption = OptionBuilder.create("P");

    Options options = new Options();
    options.addOption(configFileOption);
    options.addOption(propertiesOption);

    CommandLineParser parser = new BasicParser();
    CommandLine cmd = null;
    try {
        cmd = parser.parse(options, args);
    } catch (ParseException pe) {
        System.out.println(pe.getMessage());
        return false;
    }

    InputStream in = null;

    if (configFile == null || configFile.trim().isEmpty()) {
        configFile = cmd.getOptionValue("C");
        if (configFile != null && new File(configFile).isFile()) {
            in = new FileInputStream(configFile);
        }
    } else {
        in = MosaicHunter.class.getClassLoader().getResourceAsStream(configFile);
    }
    if (in != null) {
        try {
            ConfigManager.getInstance().loadProperties(in);
        } catch (IOException ioe) {
            System.out.println("invalid config file: " + configFile);
            return false;
        } finally {
            in.close();
        }
    }

    Properties properties = cmd.getOptionProperties("P");
    if (properties != null) {
        ConfigManager.getInstance().putAll(properties);
    }

    return !ConfigManager.getInstance().getProperties().isEmpty();
}

From source file:com.example.geomesa.authorizations.SetupUtil.java

static Options getWfsOptions() {
    Options options = new Options();

    Option geoserver = OptionBuilder.withArgName(GEOSERVER_URL).hasArg().isRequired()
            .withDescription("the base url to geoserver e.g:  https://localhost:8443/geoserver/")
            .create(GEOSERVER_URL);
    options.addOption(geoserver);//w w  w. jav  a  2s. c o  m

    Option timeout = OptionBuilder.withArgName(TIMEOUT).hasArg()
            .withDescription("the HTTP connection timeout, in milliseconds").create(TIMEOUT);
    options.addOption(timeout);

    options.addOption(OptionBuilder.withArgName(FEATURE_STORE).hasArg().isRequired().withDescription(
            "the geoserver store containing the GDELT data. Needs to be identified by <workspace>:<name>, e.g. 'geomesa:gdelt'")
            .create(FEATURE_STORE));

    return options;
}

From source file:ca.uqac.info.trace.generation.PQTraceGenerator.java

@SuppressWarnings("static-access")
@Override/*from  w w  w  .  j a va  2s  .  com*/
public Options getCommandLineOptions() {
    Options options = new Options();
    Option opt;
    opt = OptionBuilder.withArgName("x").hasArg().withDescription("Maximum arity").create("A");
    options.addOption(opt);
    opt = OptionBuilder.withArgName("x").hasArg().withDescription("Minimum arity").create("a");
    options.addOption(opt);
    opt = OptionBuilder.withArgName("x").hasArg().withDescription("Maximum number of messages to produce")
            .create("N");
    options.addOption(opt);
    opt = OptionBuilder.withArgName("x").hasArg().withDescription("Minimum number of messages to produce")
            .create("n");
    options.addOption(opt);
    opt = OptionBuilder.withArgName("x").hasArg().withDescription("Number of available parameters").create("p");
    options.addOption(opt);
    opt = OptionBuilder.withArgName("x").hasArg().withDescription("Set random seed").create("s");
    options.addOption(opt);
    options.addOption("M", false, "Messages can be multi-valued");
    options.addOption("m", false, "Messages cannot be multi-valued");
    return options;
}

From source file:edu.umd.cloud9.example.bfs.EncodeBFSGraph.java

@SuppressWarnings("static-access")
@Override/*from  w  ww. j  a  v  a 2  s .  c om*/
public int run(String[] args) throws Exception {
    Options options = new Options();
    options.addOption(
            OptionBuilder.withArgName("path").hasArg().withDescription("XML dump file").create(INPUT_OPTION));
    options.addOption(
            OptionBuilder.withArgName("path").hasArg().withDescription("output path").create(OUTPUT_OPTION));
    options.addOption(
            OptionBuilder.withArgName("nodeid").hasArg().withDescription("source node").create(SRC_OPTION));

    CommandLine cmdline;
    CommandLineParser parser = new GnuParser();
    try {
        cmdline = parser.parse(options, args);
    } catch (ParseException exp) {
        System.err.println("Error parsing command line: " + exp.getMessage());
        return -1;
    }

    if (!cmdline.hasOption(INPUT_OPTION) || !cmdline.hasOption(OUTPUT_OPTION)
            || !cmdline.hasOption(SRC_OPTION)) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(this.getClass().getName(), options);
        ToolRunner.printGenericCommandUsage(System.out);
        return -1;
    }

    String inputPath = cmdline.getOptionValue(INPUT_OPTION);
    String outputPath = cmdline.getOptionValue(OUTPUT_OPTION);
    int src = Integer.parseInt(cmdline.getOptionValue(SRC_OPTION));

    LOG.info("Tool name: " + this.getClass().getName());
    LOG.info(" - inputDir: " + inputPath);
    LOG.info(" - outputDir: " + outputPath);
    LOG.info(" - src: " + src);

    Job job = new Job(getConf(), String.format("EncodeBFSGraph[%s: %s, %s: %s, %s: %d]", INPUT_OPTION,
            inputPath, OUTPUT_OPTION, outputPath, SRC_OPTION, src));
    job.setJarByClass(EncodeBFSGraph.class);

    job.setNumReduceTasks(0);

    job.getConfiguration().setInt(SRC_OPTION, src);
    job.getConfiguration().setInt("mapred.min.split.size", 1024 * 1024 * 1024);

    FileInputFormat.addInputPath(job, new Path(inputPath));
    FileOutputFormat.setOutputPath(job, new Path(outputPath));

    job.setInputFormatClass(TextInputFormat.class);
    job.setOutputFormatClass(SequenceFileOutputFormat.class);

    job.setMapOutputKeyClass(IntWritable.class);
    job.setMapOutputValueClass(BFSNode.class);
    job.setOutputKeyClass(IntWritable.class);
    job.setOutputValueClass(BFSNode.class);

    job.setMapperClass(MyMapper.class);

    // Delete the output directory if it exists already.
    FileSystem.get(job.getConfiguration()).delete(new Path(outputPath), true);

    job.waitForCompletion(true);

    return 0;
}

From source file:calculadora.vista.VistaCLI.java

/**
 * Este metodo realiza la primera etapa de deficion de las opciones de la
 * interfaz de linea de comandos./*  w ww .  j a v  a  2s .c  o  m*/
 *
 * @see Options
 * @see Options#addOptionGroup(org.apache.commons.cli.OptionGroup)
 */
private void loadCommandLine() {
    opciones = new Options();

    //help
    opciones.addOption(new Option("h", "help", false, "Muestra este mensaje de ayuda."));

    //suma
    opciones.addOption(OptionBuilder.withArgName("num1> <num2").hasArgs(2)
            .withDescription("Calcula la suma dos numeros reales.").create("s"));
    //resta
    opciones.addOption(OptionBuilder.withArgName("num1> <num2").hasArgs(2)
            .withDescription("Calcula la resta dos numeros reales.").create("r"));
    //multiplicacion
    opciones.addOption(OptionBuilder.withArgName("num1> <num2").hasArgs(2)
            .withDescription("Calcula la multiplicacion dos numeros reales.").create("m"));
    //resto
    opciones.addOption(OptionBuilder.withArgName("num1> <num2").hasArgs(2)
            .withDescription("Calcula el resto de dos numeros reales.").create("re"));

    //division
    opciones.addOption(OptionBuilder.withArgName("dividendo> <divisor").hasArgs(2)
            .withDescription("Calcula la division de dos numeros reales.").create("d"));
    //potencia
    opciones.addOption(OptionBuilder.withArgName("base> <exp").hasArgs(2)
            .withDescription("Calcula la potencia " + " de base elevado a expontente.").create("p"));
    //raiz
    opciones.addOption(OptionBuilder.withArgName("radicando> <indice").hasArgs(2)
            .withDescription("Calcula la raiz enesima " + "de dos numeros, radicando e indice.").create("ra"));

    //Operaciones trigonometricas POSIX largo
    //seno
    opciones.addOption(OptionBuilder.withArgName("angulo").hasArgs().withLongOpt("seno")
            .withDescription("Calcula el seno de un angulo.").create());
    //coseno
    opciones.addOption(OptionBuilder.withArgName("angulo").hasArgs().withLongOpt("coseno")
            .withDescription("Calcula el coseno de un angulo.").create());
    //tangente
    opciones.addOption(OptionBuilder.withArgName("angulo").hasArgs().withLongOpt("tangente")
            .withDescription("Calcula la tangente de un angulo.").create());

    //Tablas de verdad POSIX largo
    //and
    opciones.addOption(OptionBuilder.withArgName("boolean> <boolean").hasArgs(2).withLongOpt("and")
            .withDescription("Calcula la tabla de verdad segun AND.").create());
    //or
    opciones.addOption(OptionBuilder.withArgName("boolean> <boolean").hasArgs(2).withLongOpt("or")
            .withDescription("Calcula la tabla de verdad segun OR.").create());
    //xor
    opciones.addOption(OptionBuilder.withArgName("boolean> <boolean").hasArgs(2).withLongOpt("xor")
            .withDescription("Calcula la tabla de verdad segun XOR.").create());
    //not
    opciones.addOption(OptionBuilder.withArgName("!boolean").hasArgs().withLongOpt("not")
            .withDescription("Calcula la tabla de verdad segun NOT.").create());

    //Conversiones con propiedad 
    //Fuera del grupo para poder poner la ayuda con este comando
    opciones.addOption(OptionBuilder.withArgName("property=value").hasArgs(3)
            .withDescription("Conversion entre binario, octal, decimal "
                    + "y hexadecimal, para mas informacion -h o " + "--help seguido de -Dconvert.")
            .withValueSeparator().create("D"));
}

From source file:code.DemoWordCount.java

/**
 * Runs this tool./*from w w  w.  j  a va 2 s.  co  m*/
 */
@SuppressWarnings({ "static-access" })
public int run(String[] args) throws Exception {
    Options options = new Options();

    options.addOption(OptionBuilder.withArgName("path").hasArg().withDescription("input path").create(INPUT));
    options.addOption(OptionBuilder.withArgName("path").hasArg().withDescription("output path").create(OUTPUT));
    options.addOption(OptionBuilder.withArgName("num").hasArg().withDescription("number of reducers")
            .create(NUM_REDUCERS));

    CommandLine cmdline;
    CommandLineParser parser = new GnuParser();

    try {
        cmdline = parser.parse(options, args);
    } catch (ParseException exp) {
        System.err.println("Error parsing command line: " + exp.getMessage());
        return -1;
    }

    if (!cmdline.hasOption(INPUT) || !cmdline.hasOption(OUTPUT)) {
        System.out.println("args: " + Arrays.toString(args));
        HelpFormatter formatter = new HelpFormatter();
        formatter.setWidth(120);
        formatter.printHelp(this.getClass().getName(), options);
        ToolRunner.printGenericCommandUsage(System.out);
        return -1;
    }

    String inputPath = cmdline.getOptionValue(INPUT);
    String outputPath = cmdline.getOptionValue(OUTPUT);
    int reduceTasks = cmdline.hasOption(NUM_REDUCERS) ? Integer.parseInt(cmdline.getOptionValue(NUM_REDUCERS))
            : 1;

    LOG.info("Tool: " + DemoWordCount.class.getSimpleName());
    LOG.info(" - input path: " + inputPath);
    LOG.info(" - output path: " + outputPath);
    LOG.info(" - number of reducers: " + reduceTasks);

    Configuration conf = getConf();
    Job job = Job.getInstance(conf);
    job.setJobName(DemoWordCount.class.getSimpleName());
    job.setJarByClass(DemoWordCount.class);

    job.setNumReduceTasks(reduceTasks);

    FileInputFormat.setInputPaths(job, new Path(inputPath));
    FileOutputFormat.setOutputPath(job, new Path(outputPath));

    job.setOutputKeyClass(Text.class);
    job.setOutputValueClass(IntWritable.class);

    job.setMapperClass(MyMapper.class);
    job.setCombinerClass(MyReducer.class);
    job.setReducerClass(MyReducer.class);

    // Delete the output directory if it exists already.
    Path outputDir = new Path(outputPath);
    FileSystem.get(conf).delete(outputDir, true);

    long startTime = System.currentTimeMillis();
    job.waitForCompletion(true);
    LOG.info("Job Finished in " + (System.currentTimeMillis() - startTime) / 1000.0 + " seconds");

    return 0;
}