/** * Throw a {@link MissingArgumentException} if the current option * didn't receive the number of arguments expected. */ private void checkRequiredArgs() throws ParseException { if (currentOption != null && currentOption.requiresArg()) { throw new MissingArgumentException(currentOption); } }
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; }
sshHostKeyFile = line.getOptionValue("sh", "cfg/hostkeys.ser"); } catch (MissingArgumentException e) { System.out.println("ERROR: " + e.getMessage()); System.exit(1); } catch (IllegalAccessError | UnrecognizedOptionException e) {
System.exit(-2); } catch (MissingArgumentException ex) { System.err.println("Missing argument: " + ex.getMessage()); printHelp(); System.exit(-2);
throw new MissingArgumentException(opt);
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; }
/***************************************************************************** * {@link Runnable} Interface ****************************************************************************/ public void run(String[] args) throws IOException { if (needsHelp(args)) { printHelp(); System.exit(0); } try { CommandLine cli = _parser.parse(_options, args, true); runApplication(cli, args); } catch (MissingOptionException ex) { System.err.println("Missing argument: " + ex.getMessage()); printHelp(); } catch (MissingArgumentException ex) { System.err.println("Missing argument: " + ex.getMessage()); printHelp(); } catch (UnrecognizedOptionException ex) { System.err.println("Unknown argument: " + ex.getMessage()); printHelp(); } catch (AlreadySelectedException ex) { System.err.println("Argument already selected: " + ex.getMessage()); printHelp(); } catch (ParseException ex) { System.err.println(ex.getMessage()); printHelp(); } catch (Exception ex) { ex.printStackTrace(); } }
@Override public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws Exception { final String tableName = OptUtil.getTableOpt(cl, shellState); final boolean decode = cl.hasOption(base64Opt.getOpt()); final TreeSet<Text> splits = new TreeSet<>(); if (cl.hasOption(optSplitsFile.getOpt())) { splits.addAll(ShellUtil.scanFile(cl.getOptionValue(optSplitsFile.getOpt()), decode)); } else { if (cl.getArgList().isEmpty()) { throw new MissingArgumentException("No split points specified"); } for (String s : cl.getArgs()) { splits.add(new Text(s.getBytes(Shell.CHARSET))); } } if (!shellState.getAccumuloClient().tableOperations().exists(tableName)) { throw new TableNotFoundException(null, tableName, null); } shellState.getAccumuloClient().tableOperations().addSplits(tableName, splits); return 0; }
public static GalenActionDumpArguments parse(String[] args) { args = ArgumentsUtils.processSystemProperties(args); Options options = new Options(); options.addOption("u", "url", true, "Initial test url"); options.addOption("s", "size", true, "Browser window size"); options.addOption("W", "max-width", true, "Maximum width of element area image"); options.addOption("H", "max-height", true, "Maximum height of element area image"); options.addOption("E", "export", true, "Export path for page dump"); options.addOption("c", "config", true, "Path to config"); 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); } GalenActionDumpArguments arguments = new GalenActionDumpArguments(); arguments.setUrl(cmd.getOptionValue("u")); arguments.setScreenSize(convertScreenSize(cmd.getOptionValue("s"))); arguments.setMaxWidth(parseOptionalInt(cmd.getOptionValue("W"))); arguments.setMaxHeight(parseOptionalInt(cmd.getOptionValue("H"))); arguments.setExport(cmd.getOptionValue("E")); arguments.setPaths(asList(cmd.getArgs())); arguments.setConfig(cmd.getOptionValue("c")); return arguments; }
line = parser.parse(options, argv); } catch (MissingArgumentException e) { System.out.println("ERROR: " + e.getMessage()); HelpFormatter myhelp = new HelpFormatter(); myhelp.printHelp("MediaFilterManager\n", options);
throw new MissingArgumentException("No terms specified");
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);
class myFileReaderThatStarts with arguments { class MissingArgumentException extends Exception{ MissingArgumentException(String s) { super(s); } } public static void main(String[] args) throws MissingArgumentException { //You can test args array for value if(args.length>0) { // do something with args[0] } else { // default in a path // or throw new MissingArgumentException("You need to start this program with a path"); } }
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);
/** * Helper method used by command line parsing logic to convert historical * ASC language codes into a java {@link Locale} objecst. * * @param language ASC language code to convert * @return A {@link Locale} object for the specified asc language code. * @throws MissingArgumentException Thrown if the specified language code is * not a valid asc language code. */ private static Locale getLocaleForLanguage(String language) throws MissingArgumentException { Locale result = localeMap.get(language); if (result != null) return result; throw new MissingArgumentException("Language option must be one of: " + Joiner.on(", ").join(localeMap.keySet())); }
@Test public void testDoubleDash2() throws Exception { Options options = new Options(); options.addOption(OptionBuilder.hasArg().create('n')); options.addOption(OptionBuilder.create('m')); try { parser.parse(options, new String[]{"-n", "--", "-m"}); fail("MissingArgumentException not thrown for option -n"); } catch (MissingArgumentException e) { assertNotNull("option null", e.getOption()); assertEquals("n", e.getOption().getOpt()); } }
/** * Helper method used by command line parsing logic to convert historical * ASC language codes into a java {@link Locale} objecst. * * @param language ASC language code to convert * @return A {@link Locale} object for the specified asc language code. * @throws MissingArgumentException Thrown if the specified language code is * not a valid asc language code. */ private static Locale getLocaleForLanguage(String language) throws MissingArgumentException { Locale result = localeMap.get(language); if (result != null) return result; throw new MissingArgumentException("Language option must be one of: " + Joiner.on(", ").join(localeMap.keySet())); }
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);
/** * Helper method used by command line parsing logic to convert historical * ASC language codes into a java {@link Locale} objecst. * * @param language ASC language code to convert * @return A {@link Locale} object for the specified asc language code. * @throws MissingArgumentException Thrown if the specified language code is * not a valid asc language code. */ private static Locale getLocaleForLanguage(String language) throws MissingArgumentException { Locale result = localeMap.get(language); if (result != null) return result; throw new MissingArgumentException("Language option must be one of: " + Joiner.on(", ").join(localeMap.keySet())); }