@Test public void testRequiredOption() throws Exception { Options options = PatternOptionBuilder.parsePattern("!n%m%"); CommandLineParser parser = new PosixParser(); try { parser.parse(options, new String[]{""}); fail("MissingOptionException wasn't thrown"); } catch (MissingOptionException e) { assertEquals(1, e.getMissingOptions().size()); assertTrue(e.getMissingOptions().contains("n")); } } }
@Test public void testMissingRequiredOptions() { String[] args = new String[] { "-a" }; Options options = new Options(); options.addOption("a", "enable-a", false, null); options.addOption(OptionBuilder.withLongOpt("bfile").hasArg().isRequired().create('b')); options.addOption(OptionBuilder.withLongOpt("cfile").hasArg().isRequired().create('c')); try { parser.parse(options,args); fail("exception should have been thrown"); } catch (MissingOptionException e) { assertEquals("Incorrect exception message", "Missing required options: b, c", e.getMessage()); assertTrue(e.getMissingOptions().contains("b")); assertTrue(e.getMissingOptions().contains("c")); } catch (ParseException e) { fail("expected to catch MissingOptionException"); } }
@Test public void testMissingRequiredOption() { String[] args = new String[] { "-a" }; Options options = new Options(); options.addOption("a", "enable-a", false, null); options.addOption(OptionBuilder.withLongOpt("bfile").hasArg().isRequired().create('b')); try { parser.parse(options,args); fail("exception should have been thrown"); } catch (MissingOptionException e) { assertEquals( "Incorrect exception message", "Missing required option: b", e.getMessage() ); assertTrue(e.getMissingOptions().contains("b")); } catch (ParseException e) { fail("expected to catch MissingOptionException"); } }
@Test public void testMissingRequiredGroup() throws Exception { OptionGroup group = new OptionGroup(); group.addOption(OptionBuilder.create("a")); group.addOption(OptionBuilder.create("b")); group.setRequired(true); Options options = new Options(); options.addOptionGroup(group); options.addOption(OptionBuilder.isRequired().create("c")); try { parser.parse(options, new String[] { "-c" }); fail("MissingOptionException not thrown"); } catch (MissingOptionException e) { assertEquals(1, e.getMissingOptions().size()); assertTrue(e.getMissingOptions().get(0) instanceof OptionGroup); } catch (ParseException e) { fail("Expected to catch MissingOptionException"); } }
varDict.start(); } catch (MissingOptionException e) { List<?> missingOptions = e.getMissingOptions(); System.err.print("Missing required option(s): "); for (Iterator<?> iterator = missingOptions.iterator(); iterator.hasNext();) {
throw new CommandMissingArgumentException(this, e.getOption(), e); } catch (final MissingOptionException e) { throw new CommandMissingOptionsException(this, e.getMissingOptions(), e); } catch (final ParseException e) { throw new CommandInvalidException(this, e);
throw new CommandMissingArgumentException(this, e.getOption(), e); } catch (final MissingOptionException e) { throw new CommandMissingOptionsException(this, e.getMissingOptions(), e); } catch (final ParseException e) { throw new CommandInvalidException(this, e);
throw new CommandMissingArgumentException(this, e.getOption(), e); } catch (final MissingOptionException e) { throw new CommandMissingOptionsException(this, e.getMissingOptions(), e); } catch (final ParseException e) { throw new CommandInvalidException(this, e);
throw new CommandMissingArgumentException(this, e.getOption(), e); } catch (final MissingOptionException e) { throw new CommandMissingOptionsException(this, e.getMissingOptions(), e); } catch (final ParseException e) { throw new CommandInvalidException(this, e);
throw new CommandMissingArgumentException(this, e.getOption(), e); } catch (final MissingOptionException e) { throw new CommandMissingOptionsException(this, e.getMissingOptions(), e); } catch (final ParseException e) { throw new CommandInvalidException(this, e);
throw new CommandMissingArgumentException(this, e.getOption(), e); } catch (final MissingOptionException e) { throw new CommandMissingOptionsException(this, e.getMissingOptions(), e); } catch (final AlreadySelectedException e) { throw new CommandBadArgumentNumberException(this, e);
throw new CommandMissingArgumentException(this, e.getOption(), e); } catch (final MissingOptionException e) { throw new CommandMissingOptionsException(this, e.getMissingOptions(), e); } catch (final ParseException e) { throw new CommandInvalidException(this, e);
throw new CommandMissingArgumentException(this, e.getOption(), e); } catch (final MissingOptionException e) { throw new CommandMissingOptionsException(this, e.getMissingOptions(), e); } catch (final ParseException e) { throw new CommandInvalidException(this, e);
throw new CommandMissingArgumentException(this, e.getOption(), e); } catch (final MissingOptionException e) { throw new CommandMissingOptionsException(this, e.getMissingOptions(), e); } catch (final ParseException e) { throw new CommandInvalidException(this, e);
throw new CommandMissingArgumentException(this, e.getOption(), e); } catch (final MissingOptionException e) { throw new CommandMissingOptionsException(this, e.getMissingOptions(), e); } catch (final ParseException e) { throw new CommandInvalidException(this, e);
throw new CommandMissingArgumentException(this, e.getOption(), e); } catch (final MissingOptionException e) { throw new CommandMissingOptionsException(this, e.getMissingOptions(), e); } catch (final ParseException e) { throw new CommandInvalidException(this, e);
throw new CommandMissingArgumentException(this, e.getOption(), e); } catch (final MissingOptionException e) { throw new CommandMissingOptionsException(this, e.getMissingOptions(), e); } catch (final ParseException e) { throw new CommandInvalidException(this, e);
throw new CommandMissingArgumentException(this, e.getOption(), e); } catch (final MissingOptionException e) { throw new CommandMissingOptionsException(this, e.getMissingOptions(), e); } catch (final ParseException e) { throw new CommandInvalidException(this, e);
throw new CommandMissingArgumentException(this, e.getOption(), e); } catch (final MissingOptionException e) { throw new CommandMissingOptionsException(this, e.getMissingOptions(), e); } catch (final ParseException e) { throw new CommandInvalidException(this, e);
throw new ProcessingException(Messages.REQUIRED_OPTION_MISSING.format(e.getMissingOptions()));