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:de.uni_koblenz.jgralab.utilities.csv2tg.Csv2Tg.java

final protected OptionHandler createOptionHandler() {
    String toolString = "java " + this.getClass().getName();
    String versionString = JGraLab.getInfo(false);
    OptionHandler oh = new OptionHandler(toolString, versionString);

    Option schema = new Option("s", CLI_OPTION_SCHEMA, true,
            "(required): the schema according to which the graph should be constructed.");
    schema.setRequired(true);
    schema.setArgName("file");
    oh.addOption(schema);//from  ww  w  . ja v a  2s.c  om

    Option csvFiles = new Option("i", CLI_OPTION_CSV_FILES, true,
            "(required): set of csv-file containing vertex / edge instance informations.");
    csvFiles.setRequired(true);
    csvFiles.setArgs(Option.UNLIMITED_VALUES);
    csvFiles.setArgName("files_or_folder");
    csvFiles.setValueSeparator(' ');
    oh.addOption(csvFiles);

    Option output = new Option("o", CLI_OPTION_OUTPUT_FILE, true,
            "(required): the output file name, or empty for stdout");
    output.setRequired(true);
    output.setArgName("file");
    oh.addOption(output);

    return oh;
}

From source file:de.nrw.hbz.regal.sync.Syncer.java

/**
 * @param ingester/*w w  w .j  a  v  a 2s. com*/
 *            the ingester is used to pass data to the archive
 * @param downloader
 *            the downloader is used to download data from a foreign system
 * @param builder
 *            the builder assembles DigitalEntities from the downloaded data
 *            and passes it to the ingester.
 */
public Syncer(IngestInterface ingester, DownloaderInterface downloader, DigitalEntityBuilderInterface builder) {
    this.ingester = ingester;
    this.downloader = downloader;
    this.builder = builder;
    options = new Options();

    options.addOption("?", "help", false, "Print usage information");
    options.addOption("m", "mode", true, "Specify mode: \n "
            + "INIT: All PIDs will be downloaded. All pids will be updated or created.\n"
            + "SYNC: Modified or new PIDs will be downloaded and updated or created\n "
            + "CONT: All PIDs that aren't already downloaded will be downloaded and created or updated\n"
            + "UPDT: In accordance to the timestamp all modified PIDs will be reingested"
            + "PIDL: Use this mode in combination with -list to provide a file with a newline separated pidlist"
            + "DELE: Use this mode in combination with -list to provide a file with a newline separated pidlist");
    options.addOption("u", "user", true, "Specify username");
    options.addOption("p", "password", true, "Specify password");
    options.addOption("dtl", "dtl", true, "Specify digitool url");
    options.addOption("cache", "cache", true, "Specify local directory");
    options.addOption("oai", "oai", true, "Specify the OAI-PMH endpoint");
    Option setOption = new Option("set", "set", true, "Specify an OAI setSpec");
    setOption.setValueSeparator(',');
    setOption.setRequired(false);
    setOption.setOptionalArg(true);
    options.addOption(setOption);
    options.addOption("timestamp", "timestamp", true, "Specify a local file e.g. .oaitimestamp");
    options.addOption("fedoraBase", "fedoraBase", true, "The Fedora Baseurl");
    options.addOption("host", "host", true, "The Fedora Baseurl");
    options.addOption("namespace", "namespace", true, "The namespace to operate on.");
    options.addOption("list", "list", true,
            "Path to a file with a newline separated pidlist. Only needed in combination with mode PIDL and DELE.");
    options.addOption("keystoreLocation", "keystoreLocation", true, "Specify a keystore for ssl");
    options.addOption("keystorePassword", "keystorePassword", true, "Specify a keystore password for ssl");
}

From source file:fll.scheduler.GreedySolver.java

private static Options buildOptions() {
    final Options options = new Options();
    Option option = new Option(DATA_FILE_OPTION, "datafile", true, "<file> the file ");
    option.setRequired(true);
    options.addOption(option);//from  w  w w  . j a  v a  2  s.c o m

    option = new Option(OPTIMIZE_OPTION, "optimize", false, "Turn on optimization (default: false)");
    options.addOption(option);

    return options;
}

From source file:com.zimbra.cs.db.JdbcClient.java

private JdbcClient(String[] args) {
    Option opt = new Option(OPT_HELP, "help", false, "Display this help message.");
    mOptions.addOption(opt);//w w  w .  java  2  s .c om

    opt = new Option(OPT_DRIVER_CLASS, "driver-class", true, "JDBC driver class name.");
    opt.setRequired(true);
    mOptions.addOption(opt);

    opt = new Option(OPT_USER, "user", true, "User name.");
    opt.setRequired(true);
    mOptions.addOption(opt);

    opt = new Option(OPT_PASSWORD, "password", true, "Password.");
    opt.setRequired(true);
    mOptions.addOption(opt);

    opt = new Option(OPT_JDBC_URL, "jdbc-url", true, "JDBC URL used for connecting to the database server.");
    opt.setRequired(true);
    mOptions.addOption(opt);

    mOptions.addOption(OPT_BATCH, "batch", false, "Prints results without formatting, separated by tabs.");
    mOptions.addOption(OPT_SKIP_COLUMN_NAMES, "skip-column-names", false,
            "Don't write column names in results.");

    CommandLine cl = null;

    try {
        GnuParser parser = new GnuParser();
        cl = parser.parse(mOptions, args);
    } catch (ParseException e) {
        usage(e);
        System.exit(1);
    }

    if (cl.hasOption(OPT_HELP)) {
        usage(null);
        System.exit(0);
    }

    mDriverClass = cl.getOptionValue(OPT_DRIVER_CLASS);
    mUser = cl.getOptionValue(OPT_USER);
    mPassword = cl.getOptionValue(OPT_PASSWORD);
    mJdbcUrl = cl.getOptionValue(OPT_JDBC_URL);

    if (cl.hasOption(OPT_BATCH)) {
        mBatch = true;
    }
    if (cl.hasOption(OPT_SKIP_COLUMN_NAMES)) {
        mShowColumnNames = false;
    }
}

From source file:datascript.tools.DataScriptTool.java

public void parseArguments(String[] args) throws ParseException {
    if (args.length > 0) {
        fileName = args[args.length - 1];
    }/*w w  w  . j  a v  a 2 s.c  o m*/

    Option rdsOption;

    rdsOption = new Option("h", "help", false, "prints this help text and exit");
    rdsOption.setRequired(false);
    rdsOptionsToAccept.addOption(rdsOption);

    rdsOption = new Option("c", false, "check syntax");
    rdsOption.setRequired(false);
    rdsOptionsToAccept.addOption(rdsOption);

    rdsOption = new Option("out", true, "path to the directory in which the generated code is stored");
    rdsOption.setRequired(false);
    rdsOptionsToAccept.addOption(rdsOption);

    rdsOption = new Option("src", true, "path to DataScript source files");
    rdsOption.setRequired(false);
    rdsOptionsToAccept.addOption(rdsOption);

    CmdLineParser cliParser = new CmdLineParser();
    cli = cliParser.parse(rdsOptionsToAccept, args, true);
}

From source file:com.zimbra.perf.chart.ChartUtil.java

private static Options getOptions() {
    Options opts = new Options();

    opts.addOption("h", OPT_HELP, false, "prints this usage screen");

    Option confOption = new Option("c", OPT_CONF, true, "chart configuration xml files");
    confOption.setArgs(Option.UNLIMITED_VALUES);
    confOption.setRequired(true);
    opts.addOption(confOption);/*from w  ww  . j a v a  2s. c o m*/

    Option srcDirOption = new Option("s", OPT_SRCDIR, true,
            "one or more directories where the csv files are located");
    srcDirOption.setArgs(Option.UNLIMITED_VALUES);
    opts.addOption(srcDirOption);

    Option destDirOption = new Option("d", OPT_DESTDIR, true,
            "directory where the generated chart files are saved");
    opts.addOption(destDirOption);

    opts.addOption(null, OPT_TITLE, true,
            "chart title; defaults to last directory name of --" + OPT_SRCDIR + " value");

    opts.addOption(null, OPT_START_AT, true,
            "if specified, ignore all samples before this timestamp (MM/dd/yyyy HH:mm:ss)");
    opts.addOption(null, OPT_END_AT, true,
            "if specified, ignore all samples after this timestamp (MM/dd/yyyy HH:mm:ss)");

    opts.addOption(null, OPT_AGGREGATE_START_AT, true,
            "if specified, aggregate computation starts at this timestamp (MM/dd/yyyy HH:mm:ss)");
    opts.addOption(null, OPT_AGGREGATE_END_AT, true,
            "if specified, aggregate computation ends at this timestamp (MM/dd/yyyy HH:mm:ss)");

    opts.addOption(null, OPT_NO_SUMMARY, false, "skip summary data generation");

    return opts;
}

From source file:msgclient.MsgClient.java

public void parseArguments(String[] args) throws Exception {
    // Parse command line arguments
    Options options = new Options();

    Option server = new Option("s", "server", true, "server name");
    server.setRequired(true);
    options.addOption(server);// w  ww. jav a 2s. com

    Option port = new Option("p", "port", true, "server port (default 8000)");
    port.setRequired(false);
    options.addOption(port);

    Option uname = new Option("u", "username", true, "username");
    uname.setRequired(true);
    options.addOption(uname);

    Option password = new Option("w", "password", false, "password (default is none)");
    password.setRequired(false);
    options.addOption(password);

    Option peerIdentifier = new Option("m", "peer identifier", true, "peer identifier (default is none)");
    peerIdentifier.setRequired(false);
    options.addOption(peerIdentifier);

    CommandLineParser parser = new DefaultParser();
    HelpFormatter formatter = new HelpFormatter();
    CommandLine cmd;

    try {
        cmd = parser.parse(options, args);
    } catch (ParseException e) {
        System.out.println(e.getMessage());
        formatter.printHelp("msgclient", options);

        System.exit(1);
        return;
    }

    // Optional arguments
    if (cmd.hasOption("p") == true) {
        serverPort = Integer.parseInt(cmd.getOptionValue("p"));
    } else {
        serverPort = DEFAULT_PORT;
    }

    if (cmd.hasOption("w") == true) {
        serverPassword = cmd.getOptionValue("w");
    } else {
        serverPassword = "";
    }

    if (cmd.hasOption("m") == true) {
        mPeerIdentifier = cmd.getOptionValue("m");
    } else {
        mPeerIdentifier = "";
    }

    // Required arguments
    serverName = cmd.getOptionValue("s");
    serverUsername = cmd.getOptionValue("u");
}

From source file:com.opengamma.bbg.cli.BloombergCliOptions.java

private Option createOutputOption() {
    Option option = new Option("o", OUPUT_OPTION, true, "output file");
    option.setRequired(_outputRequired);
    return option;
}

From source file:in.hatimi.nosh.support.CmdLineManager.java

private Option optionFromField(Field field) {
    CmdLineOption clo = field.getAnnotation(CmdLineOption.class);
    if (clo == null) {
        return null;
    }//from  w w  w .  ja  v  a2  s.  c  o m
    Option option = new Option(clo.name(), clo.description());
    //Option option = new Option(clo.name(), clo.longName(), clo.argCount() > 0, clo.description());
    if (StringUtils.isNotBlank(clo.longName())) {
        option.setLongOpt(clo.longName());
    }
    //option.set`
    option.setArgs(clo.argCount());
    option.setRequired(clo.required());
    option.setOptionalArg(clo.optionalArg());
    option.setValueSeparator(clo.valueSeparator());

    return option;
}

From source file:de.uni_koblenz.jgralab.utilities.tg2whatever.Tg2Whatever.java

final protected OptionHandler createOptionHandler() {
    String toolString = "java " + this.getClass().getName();
    String versionString = JGraLab.getInfo(false);
    OptionHandler oh = new OptionHandler(toolString, versionString);

    Option graph = new Option("g", "graph", true, "(required): the graph to be converted");
    graph.setRequired(true);
    graph.setArgName("file");
    oh.addOption(graph);//from  ww  w  .  j av a 2 s . c  o m

    Option alternativeSchema = new Option("a", "alternative-schema", true,
            "(optional): the schema that should be used instead of the one included in the graph file");
    alternativeSchema.setRequired(false);
    graph.setArgName("file");
    oh.addOption(alternativeSchema);

    Option domains = new Option("d", "domains", false,
            "(optional): if set, domain names of attributes will be printed");
    domains.setRequired(false);
    oh.addOption(domains);

    Option edgeAttributes = new Option("e", "edgeattr", false,
            "(optional): if set, edge attributes will be printed");
    edgeAttributes.setRequired(false);
    oh.addOption(edgeAttributes);

    Option rolenames = new Option("n", "rolenames", false, "(optional): if set, role names will be printed");
    rolenames.setRequired(false);
    oh.addOption(rolenames);

    Option output = new Option("o", "output", true, "(required): the output file name, or empty for stdout");
    output.setRequired(true);
    output.setArgName("file");
    oh.addOption(output);

    Option reversed = new Option("r", "reversed", false,
            "(optional): useful if edges run from child nodes to their parents results in a tree with root node at top");
    reversed.setRequired(false);
    oh.addOption(reversed);

    Option shortenStrings = new Option("s", "shorten-strings", false,
            "(optional): if set, strings are shortened");
    shortenStrings.setRequired(false);
    oh.addOption(shortenStrings);
    return oh;
}