diff --git a/pom.xml b/pom.xml index f9612ef5f..0dd5975fd 100644 --- a/pom.xml +++ b/pom.xml @@ -216,7 +216,7 @@ 3.0.0-M5 3.0.0-M5 5.1.2 - 5.3.0 + 6.0.0 4.4.2.1 4.4.2 1.20 diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 799eb910b..d7d56a72c 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -60,6 +60,9 @@ TypeHandler should throw ParseException for an unsupported class. + + Added setter for Builder.option #33. + Update Java from version 5 to 7. @@ -104,7 +107,7 @@ Bump maven-bundle-plugin 5.1.1 -> 5.1.2. - Bump biz.aQute.bndlib.version 5.1.2 -> 5.3.0. + Bump biz.aQute.bndlib.version 5.1.2 -> 6.0.0. Bump spotbugs from 4.4.1 to 4.4.2 #70. diff --git a/src/main/java/org/apache/commons/cli/Option.java b/src/main/java/org/apache/commons/cli/Option.java index 4a8590782..7db03723e 100644 --- a/src/main/java/org/apache/commons/cli/Option.java +++ b/src/main/java/org/apache/commons/cli/Option.java @@ -51,7 +51,7 @@ public class Option implements Cloneable, Serializable { public static final class Builder { /** The name of the option */ - private final String option; + private String option; /** description of the option */ private String description; @@ -175,6 +175,19 @@ public Builder numberOfArgs(final int numberOfArgs) { return this; } + /** + * Sets the name of the Option. + * + * @param option the name of the Option + * @return this builder, to allow method chaining + * @throws IllegalArgumentException if there are any non valid Option characters in {@code opt} + * @since 1.5 + */ + public Builder option(String option) throws IllegalArgumentException { + this.option = OptionValidator.validate(option); + return this; + } + /** * Sets whether the Option can have an optional argument. * diff --git a/src/main/java/org/apache/commons/cli/Parser.java b/src/main/java/org/apache/commons/cli/Parser.java index b43c50f6e..a28d47aba 100644 --- a/src/main/java/org/apache/commons/cli/Parser.java +++ b/src/main/java/org/apache/commons/cli/Parser.java @@ -31,7 +31,7 @@ Licensed to the Apache Software Foundation (ASF) under one or more */ @Deprecated public abstract class Parser implements CommandLineParser { - /** commandline instance */ + /** CommandLine instance */ protected CommandLine cmd; /** current Options */ diff --git a/src/test/java/org/apache/commons/cli/DefaultParserTest.java b/src/test/java/org/apache/commons/cli/DefaultParserTest.java index afba65184..0fd835a16 100644 --- a/src/test/java/org/apache/commons/cli/DefaultParserTest.java +++ b/src/test/java/org/apache/commons/cli/DefaultParserTest.java @@ -32,7 +32,7 @@ public void setUp() { } @Test - public void testBuilder() throws Exception { + public void testBuilder() { parser = DefaultParser.builder() .setStripLeadingAndTrailingQuotes(false) .setAllowPartialMatching(false) diff --git a/src/test/java/org/apache/commons/cli/OptionTest.java b/src/test/java/org/apache/commons/cli/OptionTest.java index 286aa3aaf..643cbd9e5 100644 --- a/src/test/java/org/apache/commons/cli/OptionTest.java +++ b/src/test/java/org/apache/commons/cli/OptionTest.java @@ -109,6 +109,8 @@ public void testBuilderMethods() { String.class); checkOption(Option.builder("a").desc("desc").type(Integer.class).build(), "a", "desc", null, Option.UNINITIALIZED, null, false, false, defaultSeparator, Integer.class); + checkOption(Option.builder().option("a").desc("desc").type(Integer.class).build(), "a", "desc", null, Option.UNINITIALIZED, null, false, false, + defaultSeparator, Integer.class); } @Test