Example usage for org.apache.commons.cli Option setRequired

List of usage examples for org.apache.commons.cli Option setRequired

Introduction

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

Prototype

public void setRequired(boolean required) 

Source Link

Document

Sets whether this Option is mandatory.

Usage

From source file:com.tc.config.schema.setup.StandardConfigurationSetupManagerFactory.java

public static Options createOptions(ConfigMode configMode) {
    Options options = new Options();

    Option configFileOption = new Option("f", CONFIG_SPEC_ARGUMENT_NAME, true,
            "the configuration file to use, specified as a file path or URL");
    configFileOption.setArgName("file-or-URL");
    configFileOption.setType(String.class);

    if (configMode == ConfigMode.L2) {
        configFileOption.setRequired(false);
        options.addOption(configFileOption);

        Option l2NameOption = new Option("n", "name", true, "the name of this L2; defaults to the host name");
        l2NameOption.setRequired(false);
        l2NameOption.setArgName("l2-name");
        options.addOption(l2NameOption);
    } else {/*from www. j  a va  2 s . c o m*/
        configFileOption.setRequired(true);
        options.addOption(configFileOption);
    }

    return options;
}

From source file:com.linkedin.helix.examples.BootstrapProcess.java

@SuppressWarnings("static-access")
private static Options constructCommandLineOptions() {
    Option helpOption = OptionBuilder.withLongOpt(help).withDescription("Prints command-line options info")
            .create();//w w  w  . j  a  va2s . c  om

    Option zkServerOption = OptionBuilder.withLongOpt(zkServer).withDescription("Provide zookeeper address")
            .create();
    zkServerOption.setArgs(1);
    zkServerOption.setRequired(true);
    zkServerOption.setArgName("ZookeeperServerAddress(Required)");

    Option clusterOption = OptionBuilder.withLongOpt(cluster).withDescription("Provide cluster name").create();
    clusterOption.setArgs(1);
    clusterOption.setRequired(true);
    clusterOption.setArgName("Cluster name (Required)");

    Option hostOption = OptionBuilder.withLongOpt(hostAddress).withDescription("Provide host name").create();
    hostOption.setArgs(1);
    hostOption.setRequired(true);
    hostOption.setArgName("Host name (Required)");

    Option portOption = OptionBuilder.withLongOpt(hostPort).withDescription("Provide host port").create();
    portOption.setArgs(1);
    portOption.setRequired(true);
    portOption.setArgName("Host port (Required)");

    Option stateModelOption = OptionBuilder.withLongOpt(stateModel).withDescription("StateModel Type").create();
    stateModelOption.setArgs(1);
    stateModelOption.setRequired(true);
    stateModelOption.setArgName("StateModel Type (Required)");

    // add an option group including either --zkSvr or --configFile
    Option fileOption = OptionBuilder.withLongOpt(configFile)
            .withDescription("Provide file to read states/messages").create();
    fileOption.setArgs(1);
    fileOption.setRequired(true);
    fileOption.setArgName("File to read states/messages (Optional)");

    Option transDelayOption = OptionBuilder.withLongOpt(transDelay).withDescription("Provide state trans delay")
            .create();
    transDelayOption.setArgs(1);
    transDelayOption.setRequired(false);
    transDelayOption.setArgName("Delay time in state transition, in MS");

    OptionGroup optionGroup = new OptionGroup();
    optionGroup.addOption(zkServerOption);
    optionGroup.addOption(fileOption);

    Options options = new Options();
    options.addOption(helpOption);
    // options.addOption(zkServerOption);
    options.addOption(clusterOption);
    options.addOption(hostOption);
    options.addOption(portOption);
    options.addOption(stateModelOption);
    options.addOption(transDelayOption);

    options.addOptionGroup(optionGroup);

    return options;
}

From source file:com.alibaba.rocketmq.common.MixAll.java

public static Options buildCommandlineOptions(final Options options) {
    Option opt = new Option("h", "help", false, "Print help");
    opt.setRequired(false);
    options.addOption(opt);/*  www . j  a v a2 s.c  o  m*/

    opt = new Option("n", "namesrvAddr", true,
            "Name server address list, eg: 192.168.1.100:9876;192.168.1.101:9876");
    opt.setRequired(false);
    options.addOption(opt);

    return options;
}

From source file:com.genentech.chemistry.tool.sdfAggregator.SDFAggregator.java

private static void processOptions(String[] args) {
    Option opt;
    options = new Options();
    parser = new PosixParser();

    opt = new Option("in", true, "Input file oe-supported Use .sdf to specify the file type.");
    opt.setRequired(true);
    options.addOption(opt);/*from www  .j a v  a  2 s.  c o  m*/

    opt = new Option("out", true, "Output file oe-supported Use .sdf to specify the file type.");
    opt.setRequired(true);
    options.addOption(opt);

    opt = new Option("groupby", true,
            "Tags to group by (i.e. ClusterID, AssayName). Assumes tags are presorted (i.e. through SDFSorter). "
                    + "Use multiple -groupby tags to group by more than one field.");
    opt.setRequired(false);
    options.addOption(opt);
    groups = new ArrayList<String>();

    String funcListStr = getAggregationFunctionDescriptions();
    opt = new Option("function", true, "Aggregator function:\n" + funcListStr);
    opt.setRequired(true);
    options.addOption(opt);

    options.addOption("outputmode", true,
            "[all|first(def)|last] output function results to all or only first/last entry.");

    /*
     * private static void processOptions (String[] args){
     */
    try {
        cl = parser.parse(options, args);
    } catch (Exception exp) { // catch (ParseException exp) {
        System.err.println(exp.getMessage());
        exitWithHelp(options);
    }

    // TODO: Check files exist
    inFile = cl.getOptionValue("in");
    outFile = cl.getOptionValue("out");

    outputMode = OUTPUTMODE.FIRST;
    if (cl.hasOption("outputmode")) {
        String outModeStr = cl.getOptionValue("outputmode");
        if (outModeStr.matches("(?i)all"))
            outputMode = OUTPUTMODE.ALL;
        else if (outModeStr.equalsIgnoreCase("last"))
            outputMode = OUTPUTMODE.LAST;
    }

    String[] grpByArr = cl.getOptionValues("groupby");
    if (grpByArr != null)
        groups.addAll(Arrays.asList(grpByArr));

    String[] funcstr = cl.getOptionValues("function");

    aAgg = createAggregationFunction(funcstr);
}

From source file:com.twitter.hraven.etl.JobFilePreprocessor.java

/**
 * Parse command-line arguments.//from  ww w.  j  ava2s.co m
 * 
 * @param args
 *          command line arguments passed to program.
 * @return parsed command line.
 * @throws ParseException
 */
private static CommandLine parseArgs(String[] args) throws ParseException {
    Options options = new Options();

    // Cluster
    Option o = new Option("c", "cluster", true, "cluster for which jobs are processed");
    o.setArgName("cluster");
    o.setRequired(true);
    options.addOption(o);

    // Input
    o = new Option("o", "output", true, "output directory in hdfs. This is where the index files are written.");
    o.setArgName("output-path");
    o.setRequired(true);
    options.addOption(o);

    // Input
    o = new Option("i", "input", true,
            "input directory in hdfs. Default is mapred.job.tracker.history.completed.location.");
    o.setArgName("input-path");
    o.setRequired(false);
    options.addOption(o);

    // Batch
    o = new Option("b", "batchSize", true,
            "The number of files to process in one batch. Default " + DEFAULT_BATCH_SIZE);
    o.setArgName("batch-size");
    o.setRequired(false);
    options.addOption(o);

    // raw file size limit
    o = new Option("s", "rawFileSize", true,
            "The max size of file that can be loaded into raw table. Default " + DEFAULT_RAW_FILE_SIZE_LIMIT);
    o.setArgName("rawfile-size");
    o.setRequired(false);
    options.addOption(o);

    // Force
    o = new Option("f", "forceAllFiles", false,
            "Force all files in a directory to be processed, no matter the previous processingRecord. Default: false. Usefull for batch loads.");
    o.setRequired(false);
    options.addOption(o);

    // Debugging
    options.addOption("d", "debug", false, "switch on DEBUG log level");

    CommandLineParser parser = new PosixParser();
    CommandLine commandLine = null;
    try {
        commandLine = parser.parse(options, args);
    } catch (Exception e) {
        System.err.println("ERROR: " + e.getMessage() + "\n");
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(NAME + " ", options, true);
        System.exit(-1);
    }

    // Set debug level right away
    if (commandLine.hasOption("d")) {
        Logger log = Logger.getLogger(JobFileRawLoader.class);
        log.setLevel(Level.DEBUG);
    }

    return commandLine;
}

From source file:com.twitter.heron.instance.HeronInstance.java

private static CommandLine parseCommandLineArgs(String[] args) {
    Options options = new Options();

    Option topologyNameOption = new Option(CommandLineOptions.TOPOLOGY_NAME_OPTION, true, "Topology Name");
    topologyNameOption.setRequired(true);
    topologyNameOption.setType(String.class);
    options.addOption(topologyNameOption);

    Option topologyIdOption = new Option(CommandLineOptions.TOPOLOGY_ID_OPTION, true, "Topology ID");
    topologyIdOption.setRequired(true);/*ww  w. j  a v  a2  s .c o m*/
    topologyIdOption.setType(String.class);
    options.addOption(topologyIdOption);

    Option instanceIdOption = new Option(CommandLineOptions.INSTANCE_ID_OPTION, true, "Instance ID");
    instanceIdOption.setRequired(true);
    instanceIdOption.setType(String.class);
    options.addOption(instanceIdOption);

    Option componentNameOption = new Option(CommandLineOptions.COMPONENT_NAME_OPTION, true, "Component Name");
    componentNameOption.setRequired(true);
    componentNameOption.setType(String.class);
    options.addOption(componentNameOption);

    Option taskIdOption = new Option(CommandLineOptions.TASK_ID_OPTION, true, "Task ID");
    taskIdOption.setRequired(true);
    taskIdOption.setType(Integer.class);
    options.addOption(taskIdOption);

    Option componentIndexOption = new Option(CommandLineOptions.COMPONENT_INDEX_OPTION, true,
            "Component Index");
    componentIndexOption.setRequired(true);
    componentIndexOption.setType(Integer.class);
    options.addOption(componentIndexOption);

    Option stmgrIdOption = new Option(CommandLineOptions.STMGR_ID_OPTION, true, "Stream Manager ID");
    stmgrIdOption.setType(String.class);
    stmgrIdOption.setRequired(true);
    options.addOption(stmgrIdOption);

    Option stmgrPortOption = new Option(CommandLineOptions.STMGR_PORT_OPTION, true, "Stream Manager Port");
    stmgrPortOption.setType(Integer.class);
    stmgrPortOption.setRequired(true);
    options.addOption(stmgrPortOption);

    Option metricsmgrPortOption = new Option(CommandLineOptions.METRICS_MGR_PORT_OPTION, true,
            "Metrics Manager Port");
    metricsmgrPortOption.setType(Integer.class);
    metricsmgrPortOption.setRequired(true);
    options.addOption(metricsmgrPortOption);

    Option systemConfigFileOption = new Option(CommandLineOptions.SYSTEM_CONFIG_FILE, true,
            "Heron Internals Config Filename");
    systemConfigFileOption.setType(String.class);
    systemConfigFileOption.setRequired(true);
    options.addOption(systemConfigFileOption);

    Option overrideConfigFileOption = new Option(CommandLineOptions.OVERRIDE_CONFIG_FILE, true,
            "Override Config File");
    overrideConfigFileOption.setType(String.class);
    overrideConfigFileOption.setRequired(true);
    options.addOption(overrideConfigFileOption);

    Option remoteDebuggerPortOption = new Option(CommandLineOptions.REMOTE_DEBUGGER_PORT, true,
            "Remote Debugger Port");
    remoteDebuggerPortOption.setType(Integer.class);
    options.addOption(remoteDebuggerPortOption);

    CommandLineParser parser = new DefaultParser();
    HelpFormatter formatter = new HelpFormatter();
    CommandLine cmd = null;
    try {
        cmd = parser.parse(options, args);
    } catch (ParseException e) {
        System.out.println(e.getMessage());
        formatter.printHelp("Heron Instance", options);
        throw new RuntimeException("Incorrect Usage");
    }
    return cmd;
}

From source file:com.aliyun.openservices.odps.console.pub.ShowInstanceCommand.java

static Options initOptions() {
    Options opts = new Options();
    Option project_name = new Option("p", true, "project name");
    Option limit_number = new Option("limit", true, "show limit");

    project_name.setRequired(false);
    limit_number.setRequired(false);/*from www. ja  v  a2  s. c  o  m*/

    opts.addOption(project_name);
    opts.addOption(limit_number);

    return opts;
}

From source file:de.uni_koblenz.jgralab.utilities.tgschema2java.TgSchema2Java.java

private static CommandLine processCommandLineOptions(String[] args) {
    String toolString = "java " + TgSchema2Java.class.getName();
    String versionString = JGraLab.getInfo(false);
    OptionHandler oh = new OptionHandler(toolString, versionString);

    Option filename = new Option("s", "schema", true,
            "(required): specifies the .tg-file of the schema to be converted");
    filename.setRequired(true);
    filename.setArgName("file");
    oh.addOption(filename);/* w w w. ja  va2s  . c om*/

    Option compile = new Option("c", "compile", false, "(optional): if specified, the .java are compiled");
    compile.setRequired(false);
    oh.addOption(compile);

    Option jar = new Option("j", "jar", true,
            "(optional): specifies the name of the .jar-file; if omitted, no jar will be created");
    jar.setRequired(false);
    jar.setArgName("file");
    oh.addOption(jar);

    Option without_types = new Option("w", "without-types", false,
            "(optional): Don't create typespecific methods in classes");
    without_types.setRequired(false);
    oh.addOption(without_types);

    Option path = new Option("p", "path", true,
            "specifies the path to where the created files are stored; default is current folder (\".\")");
    path.setRequired(true);
    path.setArgName("path");
    oh.addOption(path);

    return oh.parse(args);
}

From source file:com.opengamma.integration.viewer.status.ViewStatusOption.java

/**
 * Creates command line options//from w  w  w  . j  a va2  s.  co  m
 * 
 * @return the command line options, not-null.
 */
public static Options createOptions() {

    Options options = new Options();

    Option portfolioNameOption = new Option(PORTFOLIO_NAME_OPT, "name", true,
            "the name of the source OpenGamma portfolio");
    portfolioNameOption.setArgName("portfolioName");
    portfolioNameOption.setRequired(true);

    Option userOption = new Option(USER_OPT, "user", true, "the username/ipaddress for computing views");
    userOption.setArgName("username/ipaddress");

    Option formatTypeOption = new Option(FORMAT_TYPE_OPT, "format", true,
            "the format of status result, default is html");
    formatTypeOption.setArgName("csv, xml, html");

    Option aggregationTypeOption = new Option(AGGREGATION_TYPE_OPT, "aggregate", true,
            "the aggregation type of result, default is no-aggregation");
    aggregationTypeOption.setArgName("TSVC, CSVT");

    Option outputOption = new Option(OUTPUT_OPT, "output", true, "the output filename");
    outputOption.setArgName("filePath");

    Option liveMarketDataOption = new Option(LIVE_MARKET_DATA_OPT, "live", true,
            "the live marketdata datasource");
    liveMarketDataOption.setArgName("datasource");

    Option userMarketDataOption = new Option(USER_MARKET_DATA_OPT, "snapshot", true,
            "the user marketdata snapshot name");
    userMarketDataOption.setArgName("snapshot name");

    Option historicalMarketDataOption = new Option(HISTORICAL_MARKET_DATA_OPT, "historical", true,
            "the historical marketdata specification");
    historicalMarketDataOption.setArgName("localdate/htsKey");

    options.addOption(portfolioNameOption);
    options.addOption(userOption);
    options.addOption(formatTypeOption);
    options.addOption(aggregationTypeOption);
    options.addOption(outputOption);
    options.addOption(liveMarketDataOption);
    options.addOption(userMarketDataOption);
    options.addOption(historicalMarketDataOption);

    return options;
}

From source file:com.linkedin.helix.mock.storage.DummyProcess.java

@SuppressWarnings("static-access")
synchronized private static Options constructCommandLineOptions() {
    Option helpOption = OptionBuilder.withLongOpt(help).withDescription("Prints command-line options info")
            .create();/*from   w w  w  .  ja  va 2  s  .co  m*/

    Option clusterOption = OptionBuilder.withLongOpt(cluster).withDescription("Provide cluster name").create();
    clusterOption.setArgs(1);
    clusterOption.setRequired(true);
    clusterOption.setArgName("Cluster name (Required)");

    Option hostOption = OptionBuilder.withLongOpt(hostAddress).withDescription("Provide host name").create();
    hostOption.setArgs(1);
    hostOption.setRequired(true);
    hostOption.setArgName("Host name (Required)");

    Option portOption = OptionBuilder.withLongOpt(hostPort).withDescription("Provide host port").create();
    portOption.setArgs(1);
    portOption.setRequired(true);
    portOption.setArgName("Host port (Required)");

    Option cmTypeOption = OptionBuilder.withLongOpt(helixManagerType)
            .withDescription("Provide cluster manager type (e.g. 'zk', 'static-file', or 'dynamic-file'")
            .create();
    cmTypeOption.setArgs(1);
    cmTypeOption.setRequired(true);
    cmTypeOption.setArgName("Clsuter manager type (e.g. 'zk', 'static-file', or 'dynamic-file') (Required)");

    // add an option group including either --zkSvr or --clusterViewFile
    Option fileOption = OptionBuilder.withLongOpt(clusterViewFile)
            .withDescription("Provide a cluster-view file for static-file based cluster manager").create();
    fileOption.setArgs(1);
    fileOption.setRequired(true);
    fileOption.setArgName("Cluster-view file (Required for static-file based cluster manager)");

    Option zkServerOption = OptionBuilder.withLongOpt(zkServer).withDescription("Provide zookeeper address")
            .create();
    zkServerOption.setArgs(1);
    zkServerOption.setRequired(true);
    zkServerOption.setArgName("ZookeeperServerAddress(Required for zk-based cluster manager)");

    //    Option rootNsOption = OptionBuilder.withLongOpt(rootNamespace)
    //        .withDescription("Provide root namespace for dynamic-file based cluster manager").create();
    //    rootNsOption.setArgs(1);
    //    rootNsOption.setRequired(true);
    //    rootNsOption.setArgName("Root namespace (Required for dynamic-file based cluster manager)");

    Option transDelayOption = OptionBuilder.withLongOpt(transDelay).withDescription("Provide state trans delay")
            .create();
    transDelayOption.setArgs(1);
    transDelayOption.setRequired(false);
    transDelayOption.setArgName("Delay time in state transition, in MS");

    OptionGroup optionGroup = new OptionGroup();
    optionGroup.addOption(zkServerOption);
    optionGroup.addOption(fileOption);
    //    optionGroup.addOption(rootNsOption);

    Options options = new Options();
    options.addOption(helpOption);
    options.addOption(clusterOption);
    options.addOption(hostOption);
    options.addOption(portOption);
    options.addOption(transDelayOption);
    options.addOption(cmTypeOption);

    options.addOptionGroup(optionGroup);

    return options;
}