@Before public void setUp() throws Exception { opts.addOption("a", false, "toggle -a"); opts.addOption("b", true, "set -b"); opts.addOption("c", "c", false, "toggle -c"); opts.addOption("d", "d", true, "set -d"); opts.addOption(OptionBuilder.hasOptionalArg().create('e')); opts.addOption(OptionBuilder.hasOptionalArg().withLongOpt("fish").create()); opts.addOption(OptionBuilder.hasOptionalArgs().withLongOpt("gravy").create()); opts.addOption(OptionBuilder.hasOptionalArgs(2).withLongOpt("hide").create()); opts.addOption(OptionBuilder.hasOptionalArgs(2).create('i')); opts.addOption(OptionBuilder.hasOptionalArgs().create('j')); String[] args = new String[] { "-a", "-b", "foo", "--c", "--d", "bar" }; Parser parser = new PosixParser(); _cl = parser.parse(opts,args); }
@Test public void testUnambiguousPartialLongOption3() throws Exception { String[] args = new String[] { "--ver=1" }; Options options = new Options(); options.addOption(OptionBuilder.withLongOpt("verbose").hasOptionalArg().create()); options.addOption(OptionBuilder.withLongOpt("help").create()); CommandLine cl = parser.parse(options, args); assertTrue("Confirm --verbose is set", cl.hasOption("verbose")); assertEquals("1", cl.getOptionValue("verbose")); }
@Test public void testUnambiguousPartialLongOption4() throws Exception { String[] args = new String[] { "-ver=1" }; Options options = new Options(); options.addOption(OptionBuilder.withLongOpt("verbose").hasOptionalArg().create()); options.addOption(OptionBuilder.withLongOpt("help").create()); CommandLine cl = parser.parse(options, args); assertTrue("Confirm --verbose is set", cl.hasOption("verbose")); assertEquals("1", cl.getOptionValue("verbose")); }
private static void newOption(final Collection<? super Option> options, @Nullable final Character shortName, final String longName, final int argCount, final boolean argOpt, @Nullable final String argName, final String description) { OptionBuilder.withLongOpt(longName); OptionBuilder.withDescription(description); if (argCount != 0) { OptionBuilder.withArgName(argName); if (argOpt) { if (argCount == 1) { OptionBuilder.hasOptionalArg(); } else if (argCount > 1) { OptionBuilder.hasOptionalArgs(argCount); } else { OptionBuilder.hasOptionalArgs(); } } else { if (argCount == 1) { OptionBuilder.hasArg(); } else if (argCount > 1) { OptionBuilder.hasArgs(argCount); } else { OptionBuilder.hasArgs(); } } } options.add(shortName == null ? OptionBuilder.create() : OptionBuilder.create(shortName)); }
@Test public void testAmbiguousLongWithoutEqualSingleDash() throws Exception { String[] args = new String[] { "-b", "-foobar" }; Options options = new Options(); options.addOption(OptionBuilder.withLongOpt("foo").hasOptionalArg().create('f')); options.addOption(OptionBuilder.withLongOpt("bar").hasOptionalArg().create('b')); CommandLine cl = parser.parse(options, args); assertTrue(cl.hasOption("b")); assertTrue(cl.hasOption("f")); assertEquals("bar", cl.getOptionValue("foo")); }
@Test public void test11456() throws Exception { // Posix Options options = new Options(); options.addOption( OptionBuilder.hasOptionalArg().create( 'a' ) ); options.addOption( OptionBuilder.hasArg().create( 'b' ) ); String[] args = new String[] { "-a", "-bvalue" }; CommandLineParser parser = new PosixParser(); CommandLine cmd = parser.parse( options, args ); assertEquals( cmd.getOptionValue( 'b' ), "value" ); // GNU options = new Options(); options.addOption( OptionBuilder.hasOptionalArg().create( 'a' ) ); options.addOption( OptionBuilder.hasArg().create( 'b' ) ); args = new String[] { "-a", "-b", "value" }; parser = new GnuParser(); cmd = parser.parse( options, args ); assertEquals( cmd.getOptionValue( 'b' ), "value" ); }
options.addOption( OptionBuilder.withArgName("extension") .hasOptionalArg() .withDescription("modify files in place; create backup if extension is given (e.g. \'.bak\')") .create('i')); options.addOption( OptionBuilder.withArgName("port") .hasOptionalArg() .withDescription("listen on a port and process inbound lines") .create('l')); options.addOption( OptionBuilder.withArgName("splitPattern") .hasOptionalArg() .withDescription("split lines using splitPattern (default '\\s') using implicit 'split' variable") .withLongOpt("autosplit")
@Test public void testAmbiguousPartialLongOption3() throws Exception { String[] args = new String[] { "--ver=1" }; Options options = new Options(); options.addOption(OptionBuilder.withLongOpt("version").create()); options.addOption(OptionBuilder.withLongOpt("verbose").hasOptionalArg().create()); boolean caught = false; try { parser.parse(options, args); } catch (AmbiguousOptionException e) { caught = true; assertEquals("Partial option", "--ver", e.getOption()); assertNotNull("Matching options null", e.getMatchingOptions()); assertEquals("Matching options size", 2, e.getMatchingOptions().size()); } assertTrue( "Confirm MissingArgumentException caught", caught ); }
@Test public void testAmbiguousPartialLongOption4() throws Exception { String[] args = new String[] { "-ver=1" }; Options options = new Options(); options.addOption(OptionBuilder.withLongOpt("version").create()); options.addOption(OptionBuilder.withLongOpt("verbose").hasOptionalArg().create()); boolean caught = false; try { parser.parse(options, args); } catch (AmbiguousOptionException e) { caught = true; assertEquals("Partial option", "-ver", e.getOption()); assertNotNull("Matching options null", e.getMatchingOptions()); assertEquals("Matching options size", 2, e.getMatchingOptions().size()); } assertTrue( "Confirm MissingArgumentException caught", caught ); }
opts.addOption("a", false, "toggle -a"); opts.addOption("c", "c", false, "toggle -c"); opts.addOption(OptionBuilder.hasOptionalArg().create('e'));
CommandLineOpts() { geteditsizeOpt = new Option("geteditsize", "return the number of uncheckpointed transactions on the NameNode"); checkpointOpt = OptionBuilder.withArgName("force") .hasOptionalArg().withDescription("checkpoint on startup").create("checkpoint");; formatOpt = new Option("format", "format the local storage during startup"); helpOpt = new Option("h", "help", false, "get help information"); options.addOption(geteditsizeOpt); options.addOption(checkpointOpt); options.addOption(formatOpt); options.addOption(helpOpt); }
/** * Adds Help to the options. */ private void addHelpCommands(Options opt) { Option help = OptionBuilder.withLongOpt(HELP) .hasOptionalArg() .withDescription("valid commands are plan | execute | query | cancel" + " | report") .create(); getHelpOptions().addOption(help); opt.addOption(help); }
CommandLineParser parser = new PosixParser(); Options opts = new Options(); opts.addOption(OptionBuilder.hasOptionalArg().create('d')); opts.addOption(OptionBuilder.hasArg().create('o')); opts.addOption(OptionBuilder.hasArgs().create('r'));
CommandLineOpts() { geteditsizeOpt = new Option("geteditsize", "return the number of uncheckpointed transactions on the NameNode"); checkpointOpt = OptionBuilder.withArgName("force") .hasOptionalArg().withDescription("checkpoint on startup").create("checkpoint");; formatOpt = new Option("format", "format the local storage during startup"); helpOpt = new Option("h", "help", false, "get help information"); options.addOption(geteditsizeOpt); options.addOption(checkpointOpt); options.addOption(formatOpt); options.addOption(helpOpt); }
private static CommandLine handleCommandline(String[] args) throws Exception { Options opts = new Options(); opts.addOption(PRIVATEKEY_CMDLINE_PARAM, true, "private key"); opts.addOption(PUBLICKEY_CMDLINE_PARAM, true, "public key"); opts.addOption(OptionBuilder.hasOptionalArg().withDescription("private key password (if one was set)").create(PRIVATEKEYPASS_CMDLINE_PARAM)); opts.addOption(CLIENTSPUBLICKEY_CMDLINE_PARAM, true, "public keys of clients"); opts.addOption(TOKENTIMEOUT_CMDLINE_PARAM, true, "timeout for the RSA token (default = 1.5 hours)"); opts.addOption(LOCALPORT_CMDLINE_PARAM, true, "Local port, where gateway listens for requests"); opts.addOption(HELP_CMDLINE_PARAM, false, "Print help message and exit."); CommandLineParser cmd = new PosixParser(); CommandLine line = cmd.parse(opts, args); if ( line.hasOption(HELP_CMDLINE_PARAM)) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("scotty-gateway", opts, true); System.exit(0); } return line; }
static void configCopyOptions(Options options) { Option cpcol = OptionBuilder .withArgName("true,false") .hasOptionalArg() .withDescription("Whether to copy document collections from source" + " to destination") Option cppm = OptionBuilder .withArgName("true,false") .hasOptionalArg() .withDescription("Whether to copy document permissions from source" + " to destination") Option cppt = OptionBuilder .withArgName("true,false") .hasOptionalArg() .withDescription("Whether to copy document properties from source" + " to destination") Option cpqt = OptionBuilder .withArgName("true,false") .hasOptionalArg() .withDescription("Whether to copy document quality from source" + " to destination") Option cpmeta = OptionBuilder .withArgName("true,false") .hasOptionalArg() .withDescription("Whether to copy document metadata from source" + " to destination")
private static Options prepareOptions() { Options options = new Options(); options.addOption(PARAM_COLLECTION, true, "specify collection (with or without bwmeta1.element.element-collection- prefix)"); options.addOption(CliParameters.CLI_SHORT_PARAM_SERV_DESCR_LOC, true, "specify repository descriptor location"); options.addOption(CliParameters.CLI_SHORT_PARAM_CTX_FILE, true, "specify custom context file"); options.addOption(PARAM_LICENSES, true, "specify licenses (colon separated if multiple)"); options.addOption(PARAM_OVERWRITE_MODE, true, "specify overwrite mode (ALWAYS (default), NEVER, IF_OLDER, ONLY_LOW_LEVELS)"); Option remove=OptionBuilder.hasOptionalArg() .withDescription( "remove old data from the collection (requires -c, forbids -o), optional date - remove before specified date, otherwise remove before start of import. Date in format :"+CliParameters.PARAM_DATE_FORMAT) .create(PARAM_REMOVE); remove.setLongOpt("remove"); options.addOption(remove); options.addOption(PARAM_INPUT_FILE, true, "specify input file"); options.addOption(PARAM_FORMAT, true, "specify format (possible values are ZIP, TAR and TGZ)"); options.addOption(PARAM_PRESERVE_TAGS, "preserve-tags", false, "preserve tags"); options.addOption(PARAM_ADD_EXCLUDE_FROM_PUBLISHING_PROCESS_TAG, "exclude-from-publishing-process", false, "add EXCLUDED_FROM_PUBLISHING_PROCESS tag to imported elements (to exclude them from DeskLight publishing process)"); options.addOption(PARAM_NO_SAVING_HISTORY, "do not save history of updated documents", false, "do not save history of updated documents"); options.addOption(PARAM_ADD_MANAGED_BY_PACKS_IMPORTER, "mark documentsas managed by packs importer", false, "mark documents as managed by packs importer"); options.addOption(CliParameters.CLI_SHORT_PARAM_HELP, false, "show help"); // authentication related options.addOption(CliParameters.CLI_SHORT_PARAM_USER, "login", true, "user login to be used when importing to secured respository"); options.addOption(CliParameters.CLI_SHORT_PARAM_PASSWD, "password", true, "user password to be used when importing to secured respository"); options.addOption(CliParameters.CLI_SHORT_PARAM_DOMAIN, "domain", true, "user domain, optional"); options.addOption(CliParameters.CLI_SHORT_PARAM_IPADDR, "ip", true, "ip"); // currently not used, IServiceDiscoverer does not propagate information about repository security status // options.addOption("F", "force-no-authn", true, "force importing for secured repository without login/password pair provided"); return options; }
options.addOption( OptionBuilder.withLongOpt( "log-file" ).hasArg().withDescription( "Log file where all build output will go (disables output color)" ).create( LOG_FILE ) ); options.addOption( OptionBuilder.withLongOpt( "show-version" ).withDescription( "Display version information WITHOUT stopping build" ).create( SHOW_VERSION ) ); options.addOption( OptionBuilder.withLongOpt( "encrypt-master-password" ).hasOptionalArg().withDescription( "Encrypt master security password" ).create( ENCRYPT_MASTER_PASSWORD ) ); options.addOption( OptionBuilder.withLongOpt( "encrypt-password" ).hasOptionalArg().withDescription( "Encrypt server password" ).create( ENCRYPT_PASSWORD ) ); options.addOption( OptionBuilder.withLongOpt( "threads" ).hasArg().withDescription( "Thread count, for instance 2.0C where C is core multiplied" ).create( THREADS ) ); options.addOption( OptionBuilder.withLongOpt( "legacy-local-repository" ).withDescription( "Use Maven 2 Legacy Local Repository behaviour, ie no use of _remote.repositories. Can also be activated by using -Dmaven.legacyLocalRepo=true" ).create( LEGACY_LOCAL_REPOSITORY ) );
result.addOption("v", VERSION_OPTION, false, "Print version number and exit."); result.addOption("x", COMPRESS_OPTION, false, "Compress output by removing some whitespaces."); result.addOption(OptionBuilder.withLongOpt(SOURCE_MAP_OPTION).hasOptionalArg().withDescription("--source-map[=FILENAME] Outputs a v3 sourcemap to the filename (or output filename.map)").create()); result.addOption(OptionBuilder.withLongOpt(SOURCE_MAP__ROOTPATH_OPTION).hasArg().withDescription("adds this path onto the sourcemap filename and less file paths").create()); result.addOption(OptionBuilder.withLongOpt(SOURCE_MAP__BASEPATH_OPTION).hasArg().withDescription("Sets sourcemap base path, defaults to current working directory.").create());
Option exportCompress = OptionBuilder .withArgName("true,false") .hasOptionalArg() .withDescription("Whether to compress the output document") .create(OUTPUT_COMPRESS);