List of usage examples for org.apache.commons.cli Option setOptionalArg
public void setOptionalArg(boolean optionalArg)
From source file:com.mebigfatguy.roomstore.RoomStore.java
private static Options createOptions() { Options options = new Options(); Option option = new Option(NICK_NAME, true, "nickname to use to access irc channels"); option.setRequired(true);//from w w w. j a va 2 s . co m options.addOption(option); option = new Option(IRCSERVER, true, "irc server url"); option.setRequired(true); options.addOption(option); option = new Option(CHANNELS, true, "space separated list of channels to connect to"); option.setRequired(true); option.setArgs(100); options.addOption(option); option = new Option(ENDPOINTS, true, "space separated list of cassandra server server/ports"); option.setOptionalArg(true); option.setRequired(false); option.setArgs(100); options.addOption(option); option = new Option(RF, true, "replication factor[default=1]"); option.setRequired(false); options.addOption(option); return options; }
From source file:net.sf.markov4jmeter.behaviormodelextractor.CmdlOptionFactory.java
/** * Creates an option with a specified number of arguments; * * @param opt/*from w ww . j av a2 s .c o m*/ * Short representation of the option (e.g. <code>"s"</code>). * @param longOpt * Long representation of the option * (e.g. <code>"source-project"</code>). * @param description * Description of the option * (e.g. <code>"Path to source project."</code>). * @param isRequired * Flag indicating whether the option is required (as a command-line * argument) or not. * @param argName * Display name for the argument value. * @param argsNum * Number of arguments; a negative value indicates an infinite sequence * of arguments. * @param hasOptionalArg * <code>true</code> if and only if the arguments are optional. * @return * An instance of {@link Option} with the specified properties. */ public static Option createOption(final String opt, final String longOpt, final String description, final boolean isRequired, final String argName, final int argsNum, final boolean hasOptionalArg) { final Option option = new Option(opt, longOpt, argsNum != 0 /* hasArg */, description); option.setRequired(isRequired); if (argsNum != 0) { // argsNum < 0 for infinite sequence of arguments; if (argName != null) { option.setArgName(argName); } // negative number of arguments implies an infinite sequence; option.setArgs((argsNum < 0) ? Integer.MAX_VALUE : argsNum); option.setValueSeparator(CmdlOptionFactory.DEFAULT_VALUE_SEPARATOR); option.setOptionalArg(hasOptionalArg); } return option; }
From source file:de.zib.scalaris.InterOpTest.java
/** * Creates the options the command line should understand. * * @return the options the program understands *//*w w w.java 2 s .c om*/ private static Options getOptions() { final Options options = new Options(); final OptionGroup group = new OptionGroup(); /* Note: arguments are set to be optional since we implement argument * checks on our own (commons.cli is not flexible enough and only * checks for the existence of a first argument) */ options.addOption(new Option("h", "help", false, "print this message")); options.addOption(new Option("v", "verbose", false, "print verbose information, e.g. the properties read")); final Option read = new Option("r", "read", true, "read an item"); read.setArgName("basekey> <language"); read.setArgs(2); read.setOptionalArg(true); group.addOption(read); final Option write = new Option("w", "write", true, "write an item"); write.setArgName("basekey"); write.setArgs(1); write.setOptionalArg(true); group.addOption(write); options.addOptionGroup(group); options.addOption(new Option("lh", "localhost", false, "gets the local host's name as known to Java (for debugging purposes)")); return options; }
From source file:edu.vt.middleware.crypt.digest.DigestCli.java
/** {@inheritDoc} */ protected void initOptions() { super.initOptions(); final Option algorithm = new Option(OPT_ALG, true, "digest algorithm name"); algorithm.setArgName("name"); algorithm.setOptionalArg(false); final Option salt = new Option(OPT_SALT, true, "initialize digest with salt before hashing data"); salt.setArgName("hex_salt"); salt.setOptionalArg(false);/* w w w . j a va 2s . c om*/ final Option infile = new Option(OPT_INFILE, true, "file to digest; defaults to STDIN"); infile.setArgName("filepath"); infile.setOptionalArg(false); final Option encoding = new Option(OPT_ENCODING, true, "output encoding format, either hex or base64"); encoding.setArgName("encoding"); encoding.setOptionalArg(false); options.addOption(algorithm); options.addOption(salt); options.addOption(infile); options.addOption(encoding); }
From source file:fr.inrialpes.exmo.align.cli.CommonCLI.java
protected Option createOptionalOption(String name, String longName, String desc, String argName) { Option opt = createOption(name, longName, desc); opt.setOptionalArg(true); opt.setArgName(argName);//from w w w.java 2s . co m return opt; }
From source file:it.jnrpe.plugins.factory.COption.java
Option toOption() { Option ret = new Option(m_sOption, m_sDescription); if (m_bArgsOptional != null) ret.setOptionalArg(m_bArgsOptional.booleanValue()); if (m_bHasArgs) { if (m_iArgsCount == null) ret.setArgs(Option.UNLIMITED_VALUES); }//w w w .j a v a2s. co m ret.setRequired(m_bRequired); if (m_iArgsCount != null) ret.setArgs(m_iArgsCount.intValue()); if (m_sArgName != null) { if (m_iArgsCount == null) ret.setArgs(Option.UNLIMITED_VALUES); ret.setArgName(m_sArgName); } if (m_sLongOpt != null) ret.setLongOpt(m_sLongOpt); if (m_sValueSeparator != null && m_sValueSeparator.length() != 0) ret.setValueSeparator(m_sValueSeparator.charAt(0)); return ret; }
From source file:edu.vt.middleware.crypt.AbstractEncryptionCli.java
/** {@inheritDoc} */ protected void initOptions() { super.initOptions(); final Option cipher = new Option(OPT_CIPHER, true, "cipher algorithm"); cipher.setArgName("algname"); cipher.setOptionalArg(false); final Option infile = new Option(OPT_INFILE, true, "file to encrypt/decrypt; defaults to STDIN"); infile.setArgName("filepath"); infile.setOptionalArg(false);/*w w w. j ava 2s. c om*/ final Option outfile = new Option(OPT_OUTFILE, true, "output file containing result; defaults to STDOUT"); outfile.setArgName("filepath"); outfile.setOptionalArg(false); final Option encoding = new Option(OPT_ENCODING, true, "ciphertext encoding format, either base64 or hex"); encoding.setArgName("format"); encoding.setOptionalArg(false); options.addOption(cipher); options.addOption(infile); options.addOption(outfile); options.addOption(encoding); options.addOption(new Option(OPT_TAIL, "tail output from operation")); }
From source file:li.strolch.runtime.main.MainStarter.java
private void configureOptions() { Options op = new Options(); Option rootPathOption = new Option("p", OPT_ROOT_PATH, true, "root path to strolch runtime"); rootPathOption.setOptionalArg(false); rootPathOption.setRequired(true);/*ww w. j a va 2s . c o m*/ op.addOption(rootPathOption); Option envOption = new Option("e", OPT_ENV, true, "environment to load from configuration file"); envOption.setOptionalArg(false); envOption.setRequired(true); op.addOption(envOption); this.options = op; }
From source file:edu.vt.middleware.crypt.signature.SignatureCli.java
/** {@inheritDoc} */ protected void initOptions() { super.initOptions(); final Option alg = new Option(OPT_ALG, true, "signature algorithm; either DSA or RSA"); alg.setArgName("name"); alg.setOptionalArg(false); final Option key = new Option(OPT_KEY, true, "DER-encoded PKCS#8 private key for signing or " + "X.509 cert/public key for verification"); key.setArgName("filepath"); key.setOptionalArg(false);/*from ww w . j a v a 2s . c om*/ final Option infile = new Option(OPT_INFILE, true, "file to sign/verify; defaults to STDIN"); infile.setArgName("filepath"); infile.setOptionalArg(false); final Option digest = new Option(OPT_DIGEST, true, "message digest algorithm used to produce encoded message to sign"); digest.setArgName("algname"); digest.setOptionalArg(false); final Option encoding = new Option(OPT_ENCODING, true, "signature encoding format, either base64 or hex"); encoding.setArgName("format"); encoding.setOptionalArg(false); final Option verify = new Option(OPT_VERIFY, true, "verify signature in given file; " + "signature encoding determined by -encoding option"); encoding.setArgName("sigfilepath"); encoding.setOptionalArg(false); options.addOption(alg); options.addOption(key); options.addOption(infile); options.addOption(digest); options.addOption(encoding); options.addOption(verify); options.addOption(new Option(OPT_SIGN, "perform sign operation")); }
From source file:edu.vt.middleware.crypt.asymmetric.AsymmetricCli.java
/** {@inheritDoc} */ protected void initOptions() { super.initOptions(); final Option genKeyPair = new Option(OPT_GENKEYPAIR, true, "generate key pair of size; " + "public key written to -out path, " + "private key written to -privkey path"); genKeyPair.setArgName("bitsize"); genKeyPair.setOptionalArg(false); final Option privKeyPath = new Option(OPT_PRIVKEYPATH, true, "output path of generated private key"); privKeyPath.setArgName("filepath"); final Option encrypt = new Option(OPT_ENCRYPT, true, "encrypt with X.509 DER-encoded public key or certificate"); encrypt.setArgName("pubkeypath"); encrypt.setOptionalArg(false);// w w w . java2 s. co m final Option decrypt = new Option(OPT_DECRYPT, true, "decrypt with PKCS#8 DER-encoded private key"); decrypt.setArgName("privkeypath"); decrypt.setOptionalArg(false); options.addOption(genKeyPair); options.addOption(privKeyPath); options.addOption(encrypt); options.addOption(decrypt); }