commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brit...@apache.org
Subject [16/50] [abbrv] commons-cli git commit: CLI-267: Add an addRequiredOption method to Options. Thanks to Ricardo Ribeiro. This also closes #7 from GitHub.
Date Thu, 08 Jun 2017 17:36:45 GMT
CLI-267: Add an addRequiredOption method to Options. Thanks to Ricardo Ribeiro. This also closes
#7 from GitHub.

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/cli/trunk@1754329 13f79535-47bb-0310-9956-ffa450edef68


Project: http://git-wip-us.apache.org/repos/asf/commons-cli/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-cli/commit/5d1d9671
Tree: http://git-wip-us.apache.org/repos/asf/commons-cli/tree/5d1d9671
Diff: http://git-wip-us.apache.org/repos/asf/commons-cli/diff/5d1d9671

Branch: refs/heads/master
Commit: 5d1d96715b36e32bc27847e84252d2c36ec0cc20
Parents: afc13c4
Author: Benedikt Ritter <britter@apache.org>
Authored: Wed Jul 27 18:40:21 2016 +0000
Committer: Benedikt Ritter <britter@apache.org>
Committed: Wed Jul 27 18:40:21 2016 +0000

----------------------------------------------------------------------
 src/changes/changes.xml                          |  3 +++
 .../java/org/apache/commons/cli/Options.java     | 19 +++++++++++++++++++
 2 files changed, 22 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-cli/blob/5d1d9671/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 38a0daf..76730ca 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -23,6 +23,9 @@
   <body>
 
     <release version="1.4" date="tba" description="tba">
+      <action type="add" dev="britter" issue="CLI-267" due-to="Ricardo Ribeiro">
+        Add an addRequiredOption method to Options
+      </action>
       <action type="fix" dev="britter" issue="CLI-266" due-to="Ravi Teja">
         HelpFormatter.setOptionComparator(null) doesn't display the values in inserted order
       </action>

http://git-wip-us.apache.org/repos/asf/commons-cli/blob/5d1d9671/src/main/java/org/apache/commons/cli/Options.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/cli/Options.java b/src/main/java/org/apache/commons/cli/Options.java
index 796fe5c..1a10153 100644
--- a/src/main/java/org/apache/commons/cli/Options.java
+++ b/src/main/java/org/apache/commons/cli/Options.java
@@ -143,6 +143,25 @@ public class Options implements Serializable
     }
 
     /**
+     * Add an option that contains a short-name and a long-name.
+     * This option is set as required.
+     * It may be specified as requiring an argument.
+     *
+     * @param opt Short single-character name of the option.
+     * @param longOpt Long multi-character name of the option.
+     * @param hasArg flag signally if an argument is required after this option
+     * @param description Self-documenting description
+     * @return the resulting Options instance
+     */
+    public Options addRequiredOption(String opt, String longOpt, boolean hasArg, String description)
+    {
+        Option option = new Option(opt, longOpt, hasArg, description);
+        option.setRequired(true);
+        addOption(option);
+        return this;
+    }
+
+    /**
      * Adds an option instance
      *
      * @param opt the option that is to be added


Mime
View raw message