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");
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()); }
@Override public Options buildCommandlineOptions(final Options options) { Option opt = new Option("b", "brokerAddr", true, "update which broker"); opt.setRequired(false); options.addOption(opt); opt = new Option("c", "clusterName", true, "update which cluster"); opt.setRequired(false); options.addOption(opt); return options; }
public static void addOption(final Options options, final String opt, final String argName, final boolean hasArg, final String description, final boolean isRequired) { final Option option = new Option(opt, hasArg, description); option.setArgName(argName); option.setRequired(isRequired); options.addOption(option); }
private static int getRequiredPositiveInt(CommandLine line, Option option) { String iterVal = line.getOptionValue(option.getOpt()); try { return Integer.parseInt(iterVal); } catch (NumberFormatException e) { String msg = "'" + option.getLongOpt() + "' value must be a positive integer."; throw new IllegalArgumentException(msg, e); } }
public static void main(final String[] args) { final Options options = new Options(); final HelpFormatter formatter = new HelpFormatter(); options.addOption(Option.builder("p").argName("password").hasArg().desc("Cleartext password to hash").build()); options.addOption(Option.builder("env").argName("name environment variable").hasArg().desc("name environment variable to read password from").build()); final CommandLine line = parser.parse(options, args); if(line.hasOption("p")) { System.out.println(hash(line.getOptionValue("p").toCharArray())); } else if(line.hasOption("env")) { final String pwd = System.getenv(line.getOptionValue("env")); if(pwd == null || pwd.isEmpty()) { formatter.printHelp("hasher.sh", options, true); System.exit(-1);
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"));
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; }
Option help = new Option("h", "help", false, "print this message"); Option version = new Option("v", "version", false, "print version information"); Option newRun = new Option("n", "new", false, "Create NLT cache entries only for new items"); Option trackerRun = new Option("t", "tracker", false, "Create NLT cache entries only for tracker items"); Option timeLimit = OptionBuilder.withLongOpt("limit").hasArg() .withValueSeparator() .withDescription("Set time limit for execution, in minutes") .create("l"); .create(); Options options = new Options(); options.addOption(help); options.addOption(version); options.addOption(newRun); options.addOption(trackerRun); CommandLineParser parser = new PosixParser(); }; CommandLine line = parser.parse(options, args); assertTrue(line.hasOption("v")); assertEquals(line.getOptionValue("l"), "10"); assertEquals(line.getOptionValue("limit"), "10"); assertEquals(line.getOptionValue("a"), "5"); assertEquals(line.getOptionValue("age"), "5");
/** * Create an instance with common options (help, verbose, etc...). * * @param cliname the name of the command * @param includeHiveConf include "hiveconf" as an option if true */ @SuppressWarnings("static-access") public CommonCliOptions(String cliname, boolean includeHiveConf) { this.cliname = cliname; // [-v|--verbose] OPTIONS.addOption(new Option("v", "verbose", false, "Verbose mode")); // [-h|--help] OPTIONS.addOption(new Option("h", "help", false, "Print help information")); if (includeHiveConf) { OPTIONS.addOption(OptionBuilder .withValueSeparator() .hasArgs(2) .withArgName("property=value") .withLongOpt("hiveconf") .withDescription("Use value for given property") .create()); } }
@Test public void testCLI18() { Options options = new Options(); options.addOption(new Option("a", "aaa", false, "aaaaaaa")); options.addOption(new Option(null, "bbb", false, "bbbbbbb dksh fkshd fkhs dkfhsdk fhskd hksdks dhfowehfsdhfkjshf skfhkshf sf jkshfk sfh skfh skf f")); options.addOption(new Option("c", null, false, "ccccccc")); HelpFormatter formatter = new HelpFormatter(); StringWriter out = new StringWriter(); formatter.printHelp(new PrintWriter(out), 80, "foobar", "dsfkfsh kdh hsd hsdh fkshdf ksdh fskdh fsdh fkshfk sfdkjhskjh fkjh fkjsh khsdkj hfskdhf skjdfh ksf khf s", options, 2, 2, "blort j jgj j jg jhghjghjgjhgjhg jgjhgj jhg jhg hjg jgjhghjg jhg hjg jhgjg jgjhghjg jg jgjhgjgjg jhg jhgjh" + '\r' + '\n' + "rarrr", true); } }
@Test public void test31148() throws ParseException { Option multiArgOption = new Option("o","option with multiple args"); multiArgOption.setArgs(1); Options options = new Options(); options.addOption(multiArgOption); Parser parser = new PosixParser(); String[] args = new String[]{}; Properties props = new Properties(); props.setProperty("o","ovalue"); CommandLine cl = parser.parse(options,args,props); assertTrue(cl.hasOption('o')); assertEquals("ovalue",cl.getOptionValue('o')); }
public static GalenActionConfigArguments parse(String[] args) { args = ArgumentsUtils.processSystemProperties(args); Options options = new Options(); options.addOption("g", "global", false, "Flag to create global config in user home directory"); 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); } GalenActionConfigArguments configArguments = new GalenActionConfigArguments(); configArguments.isGlobal = cmd.hasOption("g"); return configArguments; }
@Before public void setUp() { options = new Options(); Option algorithm = new Option("a" , "algo", true, "the algorithm which it to perform executing"); algorithm.setArgName("algorithm name"); options.addOption(algorithm); Option key = new Option("k" , "key", true, "the key the setted algorithm uses to process"); algorithm.setArgName("value"); options.addOption(key); parser = new PosixParser(); }
/** * Parse command line. */ public static CommandLine parseCommandLine(Options options, String[] args) throws ParseException { CommandLineParser parser = new DefaultParser(); CommandLine cli = parser.parse(options, args); if (cli.hasOption(StressTestUtils.HELP_OPT.getOpt())) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp( MRStressTest.class.getSimpleName(), OPTIONS); System.exit(0); } return cli; }
@Test public void testPrintSortedUsageWithNullComparator() { Options opts = new Options(); opts.addOption(new Option("c", "first")); opts.addOption(new Option("b", "second")); opts.addOption(new Option("a", "third")); HelpFormatter helpFormatter = new HelpFormatter(); helpFormatter.setOptionComparator(null); StringWriter out = new StringWriter(); helpFormatter.printUsage(new PrintWriter(out), 80, "app", opts); assertEquals("usage: app [-c] [-b] [-a]" + EOL, out.toString()); }
private static Params parseCommand(String[] args) { try { Options options = new Options(); options.addOption(new Option("l", "language", true, "language")); options.addOption(new Option("t", "thread", true, "thread")); options.addOption(new Option("f", "file", true, "script file")); options.addOption(new Option("i", "input", true, "input file")); options.addOption(new Option("s", "sleep", true, "sleep time")); options.addOption(new Option("g", "logger", true, "sleep time")); CommandLineParser commandLineParser = new PosixParser(); CommandLine commandLine = commandLineParser.parse(options, args); return readOptions(commandLine); } catch (Exception e) { e.printStackTrace(); exit(); return null; } }
public static void main(String [] args) throws ParseException, IOException, java.text.ParseException { Options options = new Options(); options.addOption(new Option("h","help", false, "Prints this message and exits.")); options.addOption(new Option("f","force", false, "Force overwrite of target file.")); PosixParser parser = new PosixParser(); CommandLine cmdline = parser.parse(options, args, false); List<String> cmdlineArgs = cmdline.getArgList(); Option [] cmdlineOptions = cmdline.getOptions(); HelpFormatter formatter = new HelpFormatter(); switch(cmdlineOptions[i].getId()) { case 'h': usage(formatter, options, 0); + cmdlineOptions[i].getId());
@Test public void test11458() throws Exception CommandLineParser parser = new PosixParser(); CommandLine cmd = parser.parse(options, args); String[] values = cmd.getOptionValues('D'); values = cmd.getOptionValues('p'); assertEquals(values[2], "file3"); Iterator<Option> iter = cmd.iterator(); while (iter.hasNext()) switch (opt.getId()) assertEquals(opt.getValue(0), "JAVA_HOME"); assertEquals(opt.getValue(1), "/opt/java"); break; case 'p': assertEquals(opt.getValue(0), "file1"); assertEquals(opt.getValue(1), "file2"); assertEquals(opt.getValue(2), "file3"); break; default: