public class ArgParser extends Object
A simple command line argument parser that provides primitive type conversion
and value checking. An application passes a template and the command line
argument array to the constructor of this class. The constructor validates
the argument list. Subsequently the application can access specific fields
from the command line using the ArgParser
's accessor methods.
If the command line includes the argument -?
then
ArgParser
displays a summary of permissible arguments and sets
its UsageOnly property to true. The calling application should simply exit if
isUsageonly
is true for the constructed ArgParser.
Constructor and Description |
---|
ArgParser(String progName,
String[] args,
String[] template)
Construct an instance that parses an array of command line arguments
according to specifications provided in a template.
|
Modifier and Type | Method and Description |
---|---|
boolean |
booleanValue(int index)
Return the boolean value of argument specified by its index in the
template
|
String |
getFlags() |
int |
getIntValue(String fieldName) |
long |
getLongValue(String fieldName) |
String |
getStringValue(String fieldName) |
String[] |
getUnparsedArray()
Array of arguments that were not parsed by this template.
|
List<String> |
getUnparsedList()
List of the arguments that were not parsed by this template.
|
int |
intValue(int index)
Return the integer value of argument specified by its index in the
template
|
boolean |
isFlag(int ch) |
boolean |
isSpecified(String fieldName)
Indicate whether the value returned for the specified field is the
default value.
|
boolean |
isUsageOnly() |
long |
longValue(int index)
Return the long value of argument specified by its index in the template
|
ArgParser |
strict() |
String |
stringValue(int index)
Return the String value of argument specified by its index in the
template
|
String |
toString() |
void |
usage()
Display a description of the permissible argument values to
System.out . |
public ArgParser(String progName, String[] args, String[] template)
Construct an instance that parses an array of command line arguments according to specifications provided in a template. The supplied template is an array of specification elements.
Command line arguments are specified by name, not by position. Each
argument must either be a flag in the form -X
(where
X is letter) or a name-value pair in the form
argname=value
. The permissible flags and
argument names are specified by the array of template strings, each of
which must have the form:
_flag|flchar|description
orargname|argtype|description
where
flchar
_flags|x|Enable the x option
.argname
argtype
int:defaultvalue:lowbound:highbound
long:defaultvalue:lowbound:highbound
String:default
public ArgParser strict()
public String[] getUnparsedArray()
public List<String> getUnparsedList()
public void usage()
System.out
.public boolean isUsageOnly()
-?
.public boolean isFlag(int ch)
ch
- The flag characterpublic String getFlags()
-a -b -c
then this method
returns "abc"
.public boolean booleanValue(int index)
index
- public String getStringValue(String fieldName)
fieldName
- Argument name of a String value specification in the template
array.public int getIntValue(String fieldName)
fieldName
- Argument name of an int value specification in the template
array.public int intValue(int index)
index
- public long getLongValue(String fieldName)
fieldName
- Argument name of a long value specification in the template
array.public long longValue(int index)
index
- public String stringValue(int index)
index
- public boolean isSpecified(String fieldName)
fieldName
- true
if the field contains its default valueCopyright © 2025 Open Identity Platform Community. All rights reserved.