Options options = new Options(); Option input = new Option("i", "input", true, "input file path"); input.setRequired(true); options.addOption(input); Option output = new Option("o", "output", true, "output file"); output.setRequired(true); options.addOption(output); HelpFormatter formatter = new HelpFormatter(); CommandLine cmd; cmd = parser.parse(options, args); } catch (ParseException e) { System.out.println(e.getMessage()); formatter.printHelp("utility-name", options); String inputFilePath = cmd.getOptionValue("input"); String outputFilePath = cmd.getOptionValue("output");
public CubeMetaExtractor() { super(); OptionGroup realizationOrProject = new OptionGroup(); realizationOrProject.addOption(OPTION_CUBE); realizationOrProject.addOption(OPTION_PROJECT); realizationOrProject.addOption(OPTION_HYBRID); realizationOrProject.addOption(OPTION_All_PROJECT); realizationOrProject.setRequired(true); options.addOptionGroup(realizationOrProject); options.addOption(OPTION_INCLUDE_SEGMENTS); options.addOption(OPTION_INCLUDE_JOB); options.addOption(OPTION_INCLUDE_SEGMENT_DETAILS); options.addOption(OPTION_INCLUDE_ONLY_JOB_OUTPUT); options.addOption(OPTION_STORAGE_TYPE); options.addOption(OPTION_ENGINE_TYPE); }
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; }
/** * Merges the given {@link Options} into a new Options object. * * @param optionsA options to merge, can be null if none * @param optionsB options to merge, can be null if none * @return */ public static Options mergeOptions(@Nullable Options optionsA, @Nullable Options optionsB) { final Options resultOptions = new Options(); if (optionsA != null) { for (Option option : optionsA.getOptions()) { resultOptions.addOption(option); } } if (optionsB != null) { for (Option option : optionsB.getOptions()) { resultOptions.addOption(option); } } return resultOptions; } }
@Override public void addRunOptions(Options baseOptions) { super.addRunOptions(baseOptions); for (Object option : allOptions.getOptions()) { baseOptions.addOption((Option) option); } }
Options opt = new Options(); opt.addOption("h", false, "Print help for this application"); opt.addOption("iter", true, "iterative num, default 50"); opt.addOption("c", true, "parameters 1, default 1"); if (args.length == 0 || cl.hasOption('h')) { HelpFormatter f = new HelpFormatter(); f.printHelp( "Tagger:\n" + "ParserTrainer [option] train_file model_file;\n", return; args = cl.getArgs(); String datafile = args[0]; String modelfile = args[1]; int maxite = Integer.parseInt(cl.getOptionValue("iter", "50")); float c = Float.parseFloat(cl.getOptionValue("c", "1"));
try { Options setPolicyOptions = new Options(); Option pathOption = OptionBuilder.hasArg() .isRequired() .withLongOpt(pathOptionName) .withDescription("Path to set policy on") .create(); setPolicyOptions.addOption(pathOption); .withDescription("Policy to set") .create(); setPolicyOptions.addOption(policyOption); String path = args.getOptionValue(pathOptionName); String policy = args.getOptionValue(policyOptionName); writeTestOutput("Error parsing options for " + command + " " + pe.getMessage()); } catch (Exception e) { writeTestOutput("Caught exception running " + command + ": " + e.getMessage());
public static void printHelpForInfo() { HelpFormatter formatter = new HelpFormatter(); formatter.setLeftPadding(5); formatter.setWidth(80); System.out.println("\nAction \"info\" shows the optimized execution plan of the program (JSON)."); System.out.println("\n Syntax: info [OPTIONS] <jar-file> <arguments>"); formatter.setSyntaxPrefix(" \"info\" action options:"); formatter.printHelp(" ", getInfoOptionsWithoutDeprecatedOptions(new Options())); System.out.println(); }
@Test public void testShortWithoutEqual() throws Exception { String[] args = new String[] { "-fbar" }; Options options = new Options(); options.addOption(OptionBuilder.withLongOpt("foo").hasArg().create('f')); CommandLine cl = parser.parse(options, args); assertEquals("bar", cl.getOptionValue("foo")); }
@Test public void testUnambiguousPartialLongOption2() throws Exception { String[] args = new String[] { "-ver" }; Options options = new Options(); options.addOption(OptionBuilder.withLongOpt("version").create()); options.addOption(OptionBuilder.withLongOpt("help").create()); CommandLine cl = parser.parse(options, args); assertTrue("Confirm --version is set", cl.hasOption("version")); }
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("dataDirs")) { new HelpFormatter().printHelp("bin/flume-ng tool fcintegritytool ", "", options, "dataDirs is required.", true); return false; } else { String[] dataDirStr = commandLine.getOptionValue("dataDirs").split(","); for (String dataDir : dataDirStr) { File f = new File(dataDir);
Options options = new Options(); options.addOption(Option.builder("h") .longOpt("help") .desc("Print a help message") .build()); options.addOption(Option.builder("t") .longOpt("test-time") .argName("MINS") .desc("How long to run the tests for in mins (defaults to " + TEST_EXECUTE_TIME_DEFAULT + ")") .build()); options.addOption(Option.builder() .longOpt("parallel") .argName("MULTIPLIER(:TOPO:COMP)?") + "(defaults to 1.0 no scaling)") .build()); options.addOption(Option.builder() .longOpt("throughput") .argName("MULTIPLIER(:TOPO:COMP)?") + "(defaults to 1.0 no scaling)") .build()); options.addOption(Option.builder() .longOpt("local-or-shuffle") .desc("replace shuffle grouping with local or shuffle grouping") .build()); options.addOption(Option.builder() .longOpt("imbalance")
private static TxnLogToolkit parseCommandLine(String[] args) throws TxnLogToolkitException, FileNotFoundException { CommandLineParser parser = new PosixParser(); Options options = new Options(); Option helpOpt = new Option("h", "help", false, "Print help message"); options.addOption(helpOpt); Option recoverOpt = new Option("r", "recover", false, "Recovery mode. Re-calculate CRC for broken entries."); options.addOption(recoverOpt); Option quietOpt = new Option("v", "verbose", false, "Be verbose in recovery mode: print all entries, not just fixed ones."); options.addOption(quietOpt); Option dumpOpt = new Option("d", "dump", false, "Dump mode. Dump all entries of the log file with printing the content of a nodepath (default)"); options.addOption(dumpOpt); Option forceOpt = new Option("y", "yes", false, "Non-interactive mode: repair all CRC errors without asking"); options.addOption(forceOpt); Option chopOpt = new Option("c", "chop", false, "Chop mode. Chop txn file to a zxid."); Option zxidOpt = new Option("z", "zxid", true, "Used with chop. Zxid to which to chop."); options.addOption(chopOpt); options.addOption(zxidOpt); if (cli.getArgs().length < 1) { printHelpAndExit(1, options); if (cli.hasOption("chop") && cli.hasOption("zxid")) { return new TxnLogToolkit(cli.getArgs()[0], cli.getOptionValue("zxid"));
@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" ); }
private String parseConfigLocation(String[] args) { Options options = new Options(); options.addOption(CLEANER_CONFIG); CommandLine cli; try { CommandLineParser parser = new DefaultParser(); cli = parser.parse(options, Arrays.copyOfRange(args, 1, args.length)); } catch (ParseException pe) { System.out.println("Command line parse exception: " + pe.getMessage()); printUsage(options); throw new RuntimeException(pe); } return cli.getOptionValue(CLEANER_CONFIG.getOpt()); }
public static GalenActionGenerateArguments parse(String[] args) { args = ArgumentsUtils.processSystemProperties(args); Options options = new Options(); options.addOption("e", "export", true, "Path to generated spec file"); options.addOption("G", "no-galen-extras", false, "Disable galen-extras expressions"); CommandLineParser parser = new PosixParser(); CommandLine cmd; try { cmd = parser.parse(options, args); } catch (MissingArgumentException e) { throw new IllegalArgumentException("Missing value for " + e.getOption().getLongOpt(), e); } catch (Exception ex) { throw new RuntimeException(ex); } GalenActionGenerateArguments arguments = new GalenActionGenerateArguments(); arguments.setExport(cmd.getOptionValue("e")); arguments.setUseGalenExtras(!cmd.hasOption("G")); if (cmd.getArgs() == null || cmd.getArgs().length < 1) { throw new IllegalArgumentException("Missing page dump file"); } arguments.setPath(cmd.getArgs()[0]); return arguments; }
@Override public void run(String[] args) { Options options = new Options(); options.addOption(HELP); options.addOption(ZK); options.addOption(JOB_NAME); options.addOption(ROOT_DIR); options.addOption(WATCH); cli = parser.parse(options, Arrays.copyOfRange(args, 1, args.length)); } catch (ParseException pe) { System.out.println( "Command line parse exception: " + pe.getMessage() ); return; if (cli.hasOption(HELP.getOpt())) { printUsage(options); return; if (!cli.hasOption(JOB_NAME.getOpt())) { log.error("Need Job Name to be specified --", JOB_NAME.getLongOpt()); throw new RuntimeException("Need Job Name to be specified"); } else { jobName = cli.getOptionValue(JOB_NAME.getOpt()); log.info("Using job name: {}", jobName);
@Test public void test15046() throws Exception { CommandLineParser parser = new PosixParser(); String[] CLI_ARGS = new String[] {"-z", "c"}; Options options = new Options(); options.addOption(new Option("z", "timezone", true, "affected option")); parser.parse(options, CLI_ARGS); //now add conflicting option options.addOption("c", "conflict", true, "conflict option"); CommandLine line = parser.parse(options, CLI_ARGS); assertEquals( line.getOptionValue('z'), "c" ); assertTrue( !line.hasOption("c") ); }
public static void main(String[] args) throws IOException Options options = new Options(); options.addOption("c", "cache", true, "cache base"); options.addOption(null, "items", true, "directory to dump items to"); options.addOption(null, "npcs", true, "directory to dump npcs to"); options.addOption(null, "objects", true, "directory to dump objects to"); options.addOption(null, "sprites", true, "directory to dump sprites to"); try cmd = parser.parse(options, args); System.err.println("Error parsing command line options: " + ex.getMessage()); System.exit(-1); return; String cache = cmd.getOptionValue("cache"); if (cmd.hasOption("items")) String itemdir = cmd.getOptionValue("items");