@Override public Options getOptions() { final Options options = new Options(); options.addOption(CONFIG_DIR_OPTION); options.addOption(REST_PORT_OPTION); options.addOption(JOB_CLASS_NAME_OPTION); options.addOption(DYNAMIC_PROPERTY_OPTION); options.addOption(CliFrontendParser.SAVEPOINT_PATH_OPTION); options.addOption(CliFrontendParser.SAVEPOINT_ALLOW_NON_RESTORED_OPTION); return options; }
private static Options buildGeneralOptions(Options opts) { Options r = new Options(); for (Object o : opts.getOptions()) r.addOption((Option) o); Option jar = OptionBuilder.withArgName("path").hasArg() .withDescription("topology jar of the submitted topology").create("jar"); r.addOption(jar); Option conf = OptionBuilder.withArgName("configuration file").hasArg() .withDescription("an application configuration file").create("conf"); r.addOption(conf); return r; }
private void printUsage() { System.out.println("Usage:"); HelpFormatter formatter = new HelpFormatter(); formatter.setWidth(200); formatter.setLeftPadding(5); formatter.setSyntaxPrefix(" Required"); Options req = new Options(); req.addOption(container); formatter.printHelp(" ", req); formatter.setSyntaxPrefix(" Optional"); Options options = new Options(); addGeneralOptions(options); addRunOptions(options); formatter.printHelp(" ", options); }
private boolean parseCommandLineOpts(String[] args) throws ParseException { Options options = new Options(); options.addOption("l", "dataDirs", true, "Comma-separated list of data " + "directories which the tool must verify. This option is mandatory") .addOption("h", "help", false, "Display help") .addOption("e", "eventValidator", true, "Fully Qualified Name of Event Validator Implementation"); Option property = OptionBuilder.withArgName("property=value") .hasArgs(2) .withValueSeparator() .withDescription("custom properties") .create("D"); options.addOption(property); CommandLine commandLine = parser.parse(options, args); if (commandLine.hasOption("help")) { new HelpFormatter().printHelp("bin/flume-ng tool fcintegritytool ", options, true); return false; if (commandLine.hasOption("eventValidator")) { try { Class<? extends EventValidator.Builder> eventValidatorClassName = (Class<? extends EventValidator.Builder>)Class.forName( commandLine.getOptionValue("eventValidator")); EventValidator.Builder eventValidatorBuilder = eventValidatorClassName.newInstance();
@Test public void testLs() throws Exception { // create the command line parser CommandLineParser parser = new PosixParser(); Options options = new Options(); options.addOption( "a", "all", false, "do not hide entries starting with ." ); options.addOption( "A", "almost-all", false, "do not list implied . and .." ); options.addOption( "b", "escape", false, "print octal escapes for nongraphic characters" ); options.addOption( OptionBuilder.withLongOpt( "block-size" ) .withDescription( "use SIZE-byte blocks" ) .hasArg() .withArgName("SIZE") .create() ); options.addOption( "B", "ignore-backups", false, "do not list implied entried ending with ~"); options.addOption( "c", false, "with -lt: sort by, and show, ctime (time of last modification of file status information) with -l:show ctime and sort by name otherwise: sort by ctime" ); options.addOption( "C", false, "list entries by columns" ); String[] args = new String[]{ "--block-size=10" }; CommandLine line = parser.parse( options, args ); assertTrue( line.hasOption( "block-size" ) ); assertEquals( line.getOptionValue( "block-size" ), "10" ); }
Options options = new Options(); options.addOption( "help", false, "print this message" ); options.addOption( "projecthelp", false, "print project help information" ); options.addOption( "version", false, "print the version information and exit" ); options.addOption( "quiet", false, "be extra quiet" ); options.addOption( "verbose", false, "be extra verbose" ); options.addOption( "debug", false, "print debug information" ); options.addOption( "logfile", true, "use given file for log" ); options.addOption( "logger", true, "the class which is to perform the logging" ); options.addOption( "listener", true, "add an instance of a class as a project listener" ); options.addOption( "buildfile", true, "use given buildfile" ); options.addOption( OptionBuilder.withDescription( "use value for given property" ) .hasArgs() .withValueSeparator() .create( 'D' ) ); options.addOption( "find", true, "search for buildfile towards the root of the filesystem and use it" ); "-projecthelp" }; CommandLine line = parser.parse( options, args ); assertEquals( line.getOptionValue( "buildfile"), "mybuild.xml" ); assertTrue( line.hasOption( "projecthelp") );
@Test public void testUnlimitedArgs() throws Exception { String[] args = new String[]{"-e", "one", "two", "-f", "alpha"}; Options options = new Options(); options.addOption(OptionBuilder.hasArgs().create("e")); options.addOption(OptionBuilder.hasArgs().create("f")); CommandLine cl = parser.parse(options, args); assertTrue("Confirm -e is set", cl.hasOption("e")); assertEquals("number of arg for -e", 2, cl.getOptionValues("e").length); assertTrue("Confirm -f is set", cl.hasOption("f")); assertEquals("number of arg for -f", 1, cl.getOptionValues("f").length); }
@Test public void test15648() throws Exception { CommandLineParser parser = new PosixParser(); final String[] args = new String[] { "-m", "\"Two Words\"" }; Option m = OptionBuilder.hasArgs().create("m"); Options options = new Options(); options.addOption( m ); CommandLine line = parser.parse( options, args ); assertEquals( "Two Words", line.getOptionValue( "m" ) ); }
@Test public void testNegativeOption() throws Exception { String[] args = new String[] { "-b", "-1"} ; options.addOption("1", false, null); CommandLine cl = parser.parse(options, args); assertEquals("-1", cl.getOptionValue("b")); }
public BeelineOptionsProcessor() { options.addOption(OptionBuilder.hasArg().withArgName("url").create('u')); options.addOption(OptionBuilder.hasArg().withArgName("username").create('n')); options.addOption(OptionBuilder.hasArg().withArgName("password").create('p')); }
options.addOption( OptionBuilder.withLongOpt("define"). withDescription("define a system property"). hasArg(true). withArgName("name=value"). create('D')); options.addOption( OptionBuilder.hasArg(false) .withDescription("usage information") .withLongOpt("help") .create('h')); options.addOption( OptionBuilder.hasArg(false) .withDescription("debug mode will print out full stack traces") .withLongOpt("debug") .create('d')); options.addOption( options.addOption( OptionBuilder.withArgName("charset") options.addOption( OptionBuilder.withArgName("script") options.addOption( options.addOption( options.addOption(
private static Options buildOptions() { Options options = new Options(); options.addOption(null, OPTION_ARTIFACTS_LONG, true, "REQUIRED string representation of artifacts"); options.addOption(null, OPTION_ARTIFACT_REPOSITORIES_LONG, true, "OPTIONAL string representation of artifact repositories"); options.addOption(null, OPTION_MAVEN_LOCAL_REPOSITORY_DIRECTORY_LONG, true, "OPTIONAL string representation of local maven repository directory path"); options.addOption(null, OPTION_PROXY_URL_LONG, true, "OPTIONAL URL representation of proxy server"); options.addOption(null, OPTION_PROXY_USERNAME_LONG, true, "OPTIONAL Username of proxy server (basic auth)"); options.addOption(null, OPTION_PROXY_PASSWORD_LONG, true, "OPTIONAL Password of proxy server (basic auth)"); return options; } }
@Test public void testPropertyOptionMultipleValues() throws Exception { Options opts = new Options(); opts.addOption(OptionBuilder.hasArgs().withValueSeparator(',').create('k')); Properties properties = new Properties(); properties.setProperty( "k", "one,two" ); String[] values = new String[] { "one", "two" }; CommandLine cmd = parse(parser, opts, null, properties); assertTrue( cmd.hasOption("k") ); assertTrue( Arrays.equals( values, cmd.getOptionValues('k') ) ); }
private static Options buildGeneralOptions(Options opts) { Options r = new Options(); for (Object o : opts.getOptions()) r.addOption((Option) o); Option workerNum = OptionBuilder.withArgName("worker num per batch").hasArg() .withDescription("number of workers to upgrade").create("n"); r.addOption(workerNum); Option comp = OptionBuilder.withArgName("component to upgrade").hasArg() .withDescription("component id to upgrade, note that only one component is allowed at a time") .create("p"); r.addOption(comp); Option workers = OptionBuilder.withArgName("workers to upgrade").hasArg() .withDescription("workers to upgrade, in the format: host1:port1,host2:port2,...").create("w"); r.addOption(workers); return r; }
@Test public void testCLI13() throws ParseException { final String debugOpt = "debug"; @SuppressWarnings("static-access") Option debug = OptionBuilder .withArgName( debugOpt ) .withDescription( "turn on debugging" ) .withLongOpt( debugOpt ) .hasArg() .create( 'd' ); Options options = new Options(); options.addOption( debug ); CommandLine commandLine = new PosixParser().parse( options, new String[]{"-d", "true"} ); assertEquals("true", commandLine.getOptionValue( debugOpt )); assertEquals("true", commandLine.getOptionValue( 'd' )); assertTrue(commandLine.hasOption( 'd')); assertTrue(commandLine.hasOption( debugOpt)); } }
private static Options buildOptions() { Options options = new Options(); options.addOption(OPTION_NAMESPACE_SHORT, OPTION_NAMESPACE_LONG, true, "REQUIRED the list of namespace to migrate."); options.addOption(OPTION_REDIS_HOST_SHORT, OPTION_REDIS_HOST_LONG, true, "Redis hostname (default: localhost)"); options.addOption(OPTION_REDIS_PORT_SHORT, OPTION_REDIS_PORT_LONG, true, "Redis port (default: 6379)"); options.addOption(null, OPTION_REDIS_PASSWORD_LONG, true, "Redis password (default: no password)"); options.addOption(OPTION_REDIS_DB_NUM_SHORT, OPTION_REDIS_DB_NUM_LONG, true, "Redis DB number (default: 0)"); return options; }
@Nonnull private Options getOptions() { Options options = new Options(); options.addOption("c", true, "Continue processing even if one of the JSON configuration file is invalid."); options.addOption("j", true, "Directory where json configuration is stored. Default is ."); options.addOption("f", true, "A single json file to execute."); options.addOption("e", false, "Run endlessly. Default false."); options.addOption("s", true, "Seconds between server job runs (not defined with cron). Default: 60"); options.addOption(OptionBuilder .withArgName("a") .withLongOpt("additionalJars") .hasArgs() .withValueSeparator(',') .withDescription("Comma delimited list of additional jars to add to the class path") .create("a")); options.addOption("h", false, "Help"); return options; } }
private static Options buildOptions() { Options options = new Options(); options.addOption(OPTION_SQL_FILE_SHORT, OPTION_SQL_FILE_LONG, true, "REQUIRED SQL file which has sql statements"); options.addOption(OPTION_SQL_TOPOLOGY_NAME_SHORT, OPTION_SQL_TOPOLOGY_NAME_LONG, true, "Topology name to submit"); options .addOption(OPTION_SQL_EXPLAIN_SHORT, OPTION_SQL_EXPLAIN_LONG, false, "Activate explain mode (topology name will be ignored)"); return options; }
public static void main(String[] args) throws Exception { LibrecTool tool = new DataDriver(); Options options = new Options(); options.addOption("build", false, "build model"); options.addOption("load", false, "load model"); options.addOption("save", false, "save model"); options.addOption("conf", true, "the path of configuration file"); options.addOption("jobconf", true, "a specified key-value pair for configuration"); options.addOption("D", true, "a specified key-value pair for configuration"); CommandLineParser parser = new DefaultParser(); CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("build")) { tool.run(args); } else if (cmd.hasOption("load")) { } else if (cmd.hasOption("save")) { } }