Options options = new Options(); options.addOption(searchApp); PosixParser parser = new PosixParser(); CommandLine cmd = parser.parse( options, args); String[] searchArgs = cmd.getOptionValues("t");
@Test public void testOrder() throws ParseException { Option optionA = new Option("a", "first"); Options opts = new Options(); opts.addOption(optionA); PosixParser posixParser = new PosixParser(); CommandLine line = posixParser.parse(opts, null); assertFalse(line.hasOption(null)); } }
"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();
"Suffix to use on created ARC files, else uses default.")); PosixParser parser = new PosixParser(); CommandLine cmdline = parser.parse(options, args, false); @SuppressWarnings("unchecked") List<String> cmdlineArgs = cmdline.getArgList();
@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)); } }
@Test public void testMissingOptionException() throws ParseException { Options options = new Options(); options.addOption(OptionBuilder.isRequired().create("f")); try { new PosixParser().parse(options, new String[0]); fail("Expected MissingOptionException to be thrown"); } catch (MissingOptionException e) { assertEquals("Missing required option: f", e.getMessage()); } }
@Test public void testMissingOptionsException() throws ParseException { Options options = new Options(); options.addOption(OptionBuilder.isRequired().create("f")); options.addOption(OptionBuilder.isRequired().create("x")); try { new PosixParser().parse(options, new String[0]); fail("Expected MissingOptionException to be thrown"); } catch (MissingOptionException e) { assertEquals("Missing required options: f, x", e.getMessage()); } }
CommandLine commandLine = null; try { commandLine = parser.parse(options, args); if (commandLine.hasOption('h')) { hf.printHelp("producer", options, true);
CommandLine commandLine = null; try { commandLine = parser.parse(options, args); if (commandLine.hasOption('h')) { hf.printHelp("producer", options, true);
public static CommandLine parseCmdLine(String[] args, Options options) { HelpFormatter hf = new HelpFormatter(); try { return new PosixParser().parse(options, args); } catch (ParseException e) { hf.printHelp("className", options, true); throw new RuntimeException("Parse command line failed", e); } } }
@Override public CommandLine parse(Options opts, String[] args, Properties props, boolean stopAtNonOption) throws ParseException { int i = args.length; while (--i >= 0 && !"--".equals(args[i])) ; CommandLine cl = super.parse(opts, i < 0 ? args : Arrays.copyOf(args, i), props, stopAtNonOption); if (i >= 0) while (++i < args.length) cl.getArgList().add(args[i]); return cl; } }
@Override public CommandLine parse(Options opts, String[] args, Properties props, boolean stopAtNonOption) throws ParseException { int i = args.length; while (--i >= 0 && !"--".equals(args[i])) ; CommandLine cl = super.parse(opts, i < 0 ? args : Arrays.copyOf(args, i), props, stopAtNonOption); if (i >= 0) while (++i < args.length) cl.getArgList().add(args[i]); return cl; } }
/** * @param arguments * the arguments to parse * @return the commandLine * @throws ParseException * exception */ public static CommandLine parsingCLI(String[] arguments) throws ParseException { Options options = getOprions(); PosixParser posix = new PosixParser(); return posix.parse(options, arguments); }
@Override public CommandLine parse(Options options, String[] arguments, Properties properties, boolean stopAtNonOption) throws ParseException { // This check isn't performed in the base library. validateProperties(options, properties); return super.parse(options, arguments, properties, stopAtNonOption); }
private CommandLine parseArgs(String[] args) { Options opts = new Options() .addOption(createOption(RunnableOptions.JAR, "Program jar location")) .addOption(createOption(RunnableOptions.RUNTIME_ARGS, "Runtime arguments")); try { return new PosixParser().parse(opts, args); } catch (ParseException e) { throw Throwables.propagate(e); } }
private static CommandLine parseDefaultCommandLine(String[] args, ConfigMode configMode) throws ConfigurationSetupException { try { if (args == null || args.length == 0) { return new PosixParser().parse(new Options(), new String[0]); } else { Options options = createOptions(configMode); return new PosixParser().parse(options, args); } } catch (ParseException pe) { throw new ConfigurationSetupException(pe.getLocalizedMessage(), pe); } }
@Override void verifyArguments(String[] args) throws CliException { try { args = new PosixParser().parse(options, args).getArgs(); super.verifyArguments(args); } catch (Exception ex) { throw new CliException("Command parameter error"); } }
public void execute(String[] args) { try { PosixParser parser = new PosixParser(); CommandLine cl = parser.parse(options, args); executeImpl(args, cl); } catch (ParseException ex) { usage(args); } }
public C process() { additionalOptions(options); try { CommandLine cli = new PosixParser().parse(options, args); process(cli); return builder.build(); } catch (ParseException e) { throw new IllegalArgumentException("invalid command line parameters; " + e); } } }
public C process() { additionalOptions(options); try { CommandLine cli = new PosixParser().parse(options, args); process(cli); return builder.build(); } catch (ParseException e) { throw new IllegalArgumentException("invalid command line parameters; " + e); } } }