summaryrefslogtreecommitdiffstats
path: root/pki/base/silent/src/argparser/ArgParser.java
diff options
context:
space:
mode:
authoralee <alee@c9f7a03b-bd48-0410-a16d-cbbf54688b0b>2009-12-03 21:21:48 +0000
committeralee <alee@c9f7a03b-bd48-0410-a16d-cbbf54688b0b>2009-12-03 21:21:48 +0000
commitd6ef121a1728987a6e776922f6683c3dada3c475 (patch)
tree830c9d7b562ec9e14f8ed65a2941f843a6fec59d /pki/base/silent/src/argparser/ArgParser.java
parent6ed5dadf92189543cfc0a4ff6c3eeb59c0ba061c (diff)
fixes for BZ 510774,531162,504030, 493418
git-svn-id: svn+ssh://svn.fedorahosted.org/svn/pki/trunk@877 c9f7a03b-bd48-0410-a16d-cbbf54688b0b
Diffstat (limited to 'pki/base/silent/src/argparser/ArgParser.java')
-rwxr-xr-xpki/base/silent/src/argparser/ArgParser.java61
1 files changed, 40 insertions, 21 deletions
diff --git a/pki/base/silent/src/argparser/ArgParser.java b/pki/base/silent/src/argparser/ArgParser.java
index cd1b777de..46251787f 100755
--- a/pki/base/silent/src/argparser/ArgParser.java
+++ b/pki/base/silent/src/argparser/ArgParser.java
@@ -676,6 +676,7 @@ public class ArgParser
int type;
int numValues;
boolean vectorResult = false;
+ boolean required = true;
String helpMsg = null;
String valueDesc = null;
@@ -1682,28 +1683,35 @@ public class ArgParser
// skip white space following conversion information
scanner.skipWhiteSpace();
- // get the help message, if any
+ // get the help message, if any
+
+ if (!scanner.atEnd())
+ { if (scanner.getc() != '#')
+ { throw new IllegalArgumentException
+ ("Illegal character(s), expecting '#'");
+ }
+ String helpInfo = scanner.substring (scanner.getIndex());
+ // look for second '#'. If there is one, then info
+ // between the first and second '#' is the value descriptor.
+ int k = helpInfo.indexOf ("#");
+ if (k != -1)
+ { rec.valueDesc = helpInfo.substring (0, k);
+ rec.helpMsg = helpInfo.substring (k+1);
+ }
+ else
+ { rec.helpMsg = helpInfo;
+ }
+ }
+ else
+ { rec.helpMsg = "";
+ }
+
+ // parse helpMsg for required/optional information if present
+ // default to required
+ if (rec.helpMsg.indexOf("(optional") != -1) {
+ rec.required = false;
+ }
- if (!scanner.atEnd())
- { if (scanner.getc() != '#')
- { throw new IllegalArgumentException
- ("Illegal character(s), expecting '#'");
- }
- String helpInfo = scanner.substring (scanner.getIndex());
- // look for second '#'. If there is one, then info
- // between the first and second '#' is the value descriptor.
- int k = helpInfo.indexOf ("#");
- if (k != -1)
- { rec.valueDesc = helpInfo.substring (0, k);
- rec.helpMsg = helpInfo.substring (k+1);
- }
- else
- { rec.helpMsg = helpInfo;
- }
- }
- else
- { rec.helpMsg = "";
- }
// add option information to match list
if (rec.convertCode == 'h' && firstHelpOption == defaultHelpOption)
{ matchList.remove (defaultHelpOption);
@@ -1743,6 +1751,17 @@ public class ArgParser
return null;
}
+ public void checkRequiredArgs() {
+ for (int i=1; i<matchList.size(); i++) {
+ Record rec = (Record)matchList.get(i);
+ StringHolder myString = (StringHolder) rec.resHolder;
+ if (((myString.value == null) || (myString.value.equals(""))) && (rec.required)) {
+ printErrorAndExit("Required parameter " + rec.nameList.name + " is not specified.");
+ }
+ }
+ }
+
+
Object getResultHolder (String arg)
{
Record rec = getRecord(arg, null);