/** * Construct a new <code>AlreadySelectedException</code> * for the specified option group. * * @param group the option group already selected * @param option the option that triggered the exception * @since 1.2 */ public AlreadySelectedException(OptionGroup group, Option option) { this("The option '" + option.getKey() + "' was specified but an option from this group " + "has already been selected: '" + group.getSelected() + "'"); this.group = group; this.option = option; }
boolean selected = group != null && group.getSelected() != null;
boolean selected = group != null && group.getSelected() != null;
@Test public void testOptionGroupLong() throws Exception { OptionGroup group = new OptionGroup(); group.addOption(OptionBuilder.withLongOpt("foo").create()); group.addOption(OptionBuilder.withLongOpt("bar").create()); Options options = new Options(); options.addOptionGroup(group); CommandLine cl = parser.parse(options, new String[] { "--bar" }); assertTrue(cl.hasOption("bar")); assertEquals("selected option", "bar", group.getSelected()); }
@Test public void testOptionGroup() throws Exception { OptionGroup group = new OptionGroup(); group.addOption(OptionBuilder.create("a")); group.addOption(OptionBuilder.create("b")); Options options = new Options(); options.addOptionGroup(group); parser.parse(options, new String[] { "-b" }); assertEquals("selected option", "b", group.getSelected()); }
@Test public void testTwoOptionsFromGroup() throws Exception { String[] args = new String[] { "-f", "-d" }; try { parser.parse( _options, args); fail( "two arguments from group not allowed" ); } catch (AlreadySelectedException e) { assertNotNull("null option group", e.getOptionGroup()); assertEquals("selected option", "f", e.getOptionGroup().getSelected()); assertEquals("option", "d", e.getOption().getOpt()); } }
@Test public void testTwoLongOptionsFromGroup() throws Exception { String[] args = new String[] { "--file", "--directory" }; try { parser.parse(_options, args); fail( "two arguments from group not allowed" ); } catch (AlreadySelectedException e) { assertNotNull("null option group", e.getOptionGroup()); assertEquals("selected option", "f", e.getOptionGroup().getSelected()); assertEquals("option", "d", e.getOption().getOpt()); } }
/** * Construct a new <code>AlreadySelectedException</code> * for the specified option group. * * @param group the option group already selected * @param option the option that triggered the exception * @since 1.2 */ public AlreadySelectedException(OptionGroup group, Option option) { this("The option '" + option.getKey() + "' was specified but an option from this group " + "has already been selected: '" + group.getSelected() + "'"); this.group = group; this.option = option; }
/** * Construct a new <code>AlreadySelectedException</code> * for the specified option group. * * @param group the option group already selected * @param option the option that triggered the exception * @since 1.2 */ public AlreadySelectedException(OptionGroup group, Option option) { this("The option '" + option.getKey() + "' was specified but an option from this group " + "has already been selected: '" + group.getSelected() + "'"); this.group = group; this.option = option; }
/** * Construct a new <code>AlreadySelectedException</code> * for the specified option group. * * @param group the option group already selected * @param option the option that triggered the exception * @since 1.2 */ public AlreadySelectedException(OptionGroup group, Option option) { this("The option '" + option.getKey() + "' was specified but an option from this group " + "has already been selected: '" + group.getSelected() + "'"); this.group = group; this.option = option; }
/** * Sets the GET method if the command line has the "get" option. */ private void setMethod() { Option opt = this.options.getOption("-get"); this.method = this.options.getOptionGroup(opt).getSelected(); }
public static void main(String[] args) { CommandLineParser parser = new DefaultParser(); HelpFormatter formatter = new HelpFormatter(); try { parser.parse(OPTIONS, args, true); if (GROUP_DIRECTION.getSelected().equals("CLI")) { CLILauncher.main((String[]) ArrayUtils.removeElement(args, "--CLI")); } else if (GROUP_DIRECTION.getSelected().equals("GUI")) { GUILauncher.main((String[]) ArrayUtils.removeElement(args, "--GUI")); } else { throw new ParseException("Unknown entry parameter..."); } } catch (Exception e) { System.err.println(e.getMessage()); formatter.printHelp("N2P-Launcher", OPTIONS); } } }
CLIUtils.addEncodingOptions(opts); CommandLine cl = CLIUtils.parseComandLine(args, opts, rb, DcmDir.class); if (cmdGroup.getSelected() == null) throw new ParseException(rb.getString("missing")); return cl;
CLIUtils.addEncodingOptions(opts); CommandLine cl = CLIUtils.parseComandLine(args, opts, rb, DcmDir.class); if (cmdGroup.getSelected() == null) throw new ParseException(rb.getString("missing")); return cl;
@SuppressWarnings("unchecked") public static void main(String[] args) throws Exception { try { OptionGroup cmdGroup = new OptionGroup(); CommandLine cl = parseComandLine(args, cmdGroup); Operation op = Operation.valueOf(cmdGroup.getSelected()); try (DcmLdap main = new DcmLdap(ldapEnv(cl))) { op.configure(main, cl); op.perform(main); } } catch (ParseException e) { System.err.println("dcmldap: " + e.getMessage()); System.err.println(rb.getString("try")); System.exit(2); } }
String oper = options.getOptionGroup(opt).getSelected(); if ("delta".equals(oper)) { isDelta = true;
} else { System.err.println("Unimplemented verb: " + verbs.getSelected());
@SuppressWarnings("unchecked") public static void main(String[] args) throws Exception { try { OptionGroup cmdGroup = new OptionGroup(); CommandLine cl = parseComandLine(args, cmdGroup); Operation op = Operation.valueOf(cmdGroup.getSelected()); try (DcmLdap main = new DcmLdap(ldapEnv(cl))) { op.configure(main, cl); op.perform(main); } } catch (ParseException e) { System.err.println("dcmldap: " + e.getMessage()); System.err.println(rb.getString("try")); System.exit(2); } }
boolean selected = group != null && group.getSelected() != null;
boolean selected = group != null && group.getSelected() != null;