commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brit...@apache.org
Subject svn commit: r1754329 - in /commons/proper/cli/trunk/src: changes/changes.xml main/java/org/apache/commons/cli/Options.java
Date Wed, 27 Jul 2016 18:40:22 GMT
Author: britter
Date: Wed Jul 27 18:40:21 2016
New Revision: 1754329

URL: http://svn.apache.org/viewvc?rev=1754329&view=rev
Log:
CLI-267: Add an addRequiredOption method to Options. Thanks to Ricardo Ribeiro. This also
closes #7 from GitHub.

Modified:
    commons/proper/cli/trunk/src/changes/changes.xml
    commons/proper/cli/trunk/src/main/java/org/apache/commons/cli/Options.java

Modified: commons/proper/cli/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/cli/trunk/src/changes/changes.xml?rev=1754329&r1=1754328&r2=1754329&view=diff
==============================================================================
--- commons/proper/cli/trunk/src/changes/changes.xml (original)
+++ commons/proper/cli/trunk/src/changes/changes.xml Wed Jul 27 18:40:21 2016
@@ -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>

Modified: commons/proper/cli/trunk/src/main/java/org/apache/commons/cli/Options.java
URL: http://svn.apache.org/viewvc/commons/proper/cli/trunk/src/main/java/org/apache/commons/cli/Options.java?rev=1754329&r1=1754328&r2=1754329&view=diff
==============================================================================
--- commons/proper/cli/trunk/src/main/java/org/apache/commons/cli/Options.java (original)
+++ commons/proper/cli/trunk/src/main/java/org/apache/commons/cli/Options.java Wed Jul 27
18:40:21 2016
@@ -143,6 +143,25 @@ public class Options implements Serializ
     }
 
     /**
+     * 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