@Test public void testOptionAndRequiredOption() throws Exception { String[] args = new String[]{"-a", "-b", "file"}; TypedOption<String> b = new TypedOption<String>().setShortName("b").setLongName("bfile").setSingleValued(true) .setDescription("set the value of [b]").setType(String.class).setRequired(true); cli.removeOption("b").addOption(b); CommandLine evaluated = cli.parse(Arrays.asList(args)); assertThat(getBooleanOption(evaluated, "a")).isTrue(); assertThat(getStringOption(evaluated, "b")).isEqualTo("file"); assertThat(evaluated.allArguments()).isEmpty(); }
@Test public void testWithRequiredOption() throws Exception { String[] args = new String[]{"-b", "file"}; TypedOption<String> b = new TypedOption<String>().setShortName("b").setLongName("bfile").setSingleValued(true) .setDescription("set the value of [b]").setType(String.class).setRequired(true); cli.removeOption("b").addOption(b); CommandLine evaluated = cli.parse(Arrays.asList(args)); assertThat(getBooleanOption(evaluated, "a")).isFalse(); assertThat((String) evaluated.getOptionValue("b")).isEqualTo("file"); assertThat(evaluated.allArguments()).isEmpty(); }
opt.setDescription(description.value());
@Test public void testMissingRequiredOption() throws Exception { String[] args = new String[]{"-a"}; TypedOption<String> b = new TypedOption<String>().setShortName("b").setLongName("bfile") .setSingleValued(true) .setDescription("set the value of [b]").setType(String.class).setRequired(true); cli.removeOption("b").addOption(b); try { cli.parse(Arrays.asList(args)); fail("exception expected"); } catch (MissingOptionException e) { assertThat(e.getExpected()).hasSize(1); } }
@Before public void setUp() { cli = new DefaultCLI(); cli.setName("test").setHidden(false).setDescription("A test command"); cli.addOption(new TypedOption<Boolean>().setType(Boolean.class).setShortName("a").setLongName("enable-a") .setFlag(true).setDescription("turn [a] on or off")); cli.addOption(new TypedOption<String>().setType(String.class).setShortName("b").setLongName("bfile").setSingleValued(true) .setDescription("set the value of [b]")); cli.addOption(new TypedOption<Boolean>().setType(Boolean.class).setShortName("c").setLongName("copt").setSingleValued(false) .setDescription("turn [c] on or off")); }
@Test public void testMissingRequiredOptions() throws CLIException { String[] args = new String[]{"-a"}; TypedOption<String> b = new TypedOption<String>().setShortName("b").setLongName("bfile").setSingleValued(true) .setDescription("set the value of [b]").setType(String.class).setRequired(true); TypedOption<Boolean> c = new TypedOption<Boolean>().setShortName("c").setLongName("copt").setSingleValued(false) .setDescription("turn [c] on or off").setType(Boolean.class).setRequired(true); cli.removeOption("b").addOption(b).removeOption("c").addOption(c); try { CommandLine evaluated = cli.parse(Arrays.asList(args)); fail("exception expected"); } catch (MissingOptionException e) { assertThat(e.getExpected()).hasSize(2); } }
@Test public void testOptionAndRequiredOption() throws Exception { String[] args = new String[]{"-a", "-b", "file"}; TypedOption<String> b = new TypedOption<String>().setShortName("b").setLongName("bfile").setSingleValued(true) .setDescription("set the value of [b]").setType(String.class).setRequired(true); cli.removeOption("b").addOption(b); CommandLine evaluated = cli.parse(Arrays.asList(args)); assertThat(getBooleanOption(evaluated, "a")).isTrue(); assertThat(getStringOption(evaluated, "b")).isEqualTo("file"); assertThat(evaluated.allArguments()).isEmpty(); }
@Test public void testWithRequiredOption() throws Exception { String[] args = new String[]{"-b", "file"}; TypedOption<String> b = new TypedOption<String>().setShortName("b").setLongName("bfile").setSingleValued(true) .setDescription("set the value of [b]").setType(String.class).setRequired(true); cli.removeOption("b").addOption(b); CommandLine evaluated = cli.parse(Arrays.asList(args)); assertThat(getBooleanOption(evaluated, "a")).isFalse(); assertThat((String) evaluated.getOptionValue("b")).isEqualTo("file"); assertThat(evaluated.allArguments()).isEmpty(); }
opt.setDescription(description.value());
@Before public void setUp() { cli = new DefaultCLI(); cli.setName("test").setHidden(false).setDescription("A test command"); cli.addOption(new TypedOption<Boolean>().setType(Boolean.class).setShortName("a").setLongName("enable-a") .setFlag(true).setDescription("turn [a] on or off")); cli.addOption(new TypedOption<String>().setType(String.class).setShortName("b").setLongName("bfile").setSingleValued(true) .setDescription("set the value of [b]")); cli.addOption(new TypedOption<Boolean>().setType(Boolean.class).setShortName("c").setLongName("copt").setSingleValued(false) .setDescription("turn [c] on or off")); }
@Test public void testMissingRequiredOption() throws Exception { String[] args = new String[]{"-a"}; TypedOption<String> b = new TypedOption<String>().setShortName("b").setLongName("bfile") .setSingleValued(true) .setDescription("set the value of [b]").setType(String.class).setRequired(true); cli.removeOption("b").addOption(b); try { cli.parse(Arrays.asList(args)); fail("exception expected"); } catch (MissingOptionException e) { assertThat(e.getExpected()).hasSize(1); } }
@Test public void testMissingRequiredOptions() throws CLIException { String[] args = new String[]{"-a"}; TypedOption<String> b = new TypedOption<String>().setShortName("b").setLongName("bfile").setSingleValued(true) .setDescription("set the value of [b]").setType(String.class).setRequired(true); TypedOption<Boolean> c = new TypedOption<Boolean>().setShortName("c").setLongName("copt").setSingleValued(false) .setDescription("turn [c] on or off").setType(Boolean.class).setRequired(true); cli.removeOption("b").addOption(b).removeOption("c").addOption(c); try { CommandLine evaluated = cli.parse(Arrays.asList(args)); fail("exception expected"); } catch (MissingOptionException e) { assertThat(e.getExpected()).hasSize(2); } }