|
Lightweight Bartering Grid | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectlbg.common.io.ArgsParser
public class ArgsParser
A parser for command-line arguments.
Supports optional and required parameters, short and long options,
flags and arguments taking a list of values.
Currently doesn't support arguments strings with a inderminate number of
parameters at the end (like a list of files grep-style). Can be easily
bypassed with a OptionType.LIST option.
addIntOption(char, String, boolean, Integer, String)
requires a default value if option isn't required.
Constructor Summary | |
---|---|
ArgsParser(java.lang.String program)
Prepare an argument parser. |
Method Summary | |
---|---|
void |
addFlag(char sh,
java.lang.String lg,
java.lang.String desc)
Register a flag for the Arguments Parser. |
void |
addHelper(char sh,
java.lang.String lg,
java.lang.String desc)
Adds a special kind of flag that will cause the parser to stop without paying attention to the rest of the command line. |
void |
addIntOption(char sh,
java.lang.String lg,
boolean required,
java.lang.Integer defValue,
java.lang.String desc)
Register an int option for the Arguments Parser. |
void |
addListOption(char sh,
java.lang.String lg,
boolean required,
java.lang.String desc)
Register an list option for the Arguments Parser. |
void |
addStringOption(char sh,
java.lang.String lg,
boolean required,
java.lang.String defValue,
java.lang.String desc)
Register a string option for the Arguments Parser. |
boolean |
getFlag(char sh)
Get value of flag sh. |
boolean |
getFlag(java.lang.String lg)
Get value of flag lg. |
int |
intValueOf(char sh)
Get value of option sh as an int. |
int |
intValueOf(java.lang.String lg)
Get value of option lg as an int. |
java.lang.String[] |
listValueOf(char sh)
Get value of option sh as a string array. |
java.lang.String[] |
listValueOf(java.lang.String lg)
Get value of option lg as a string array. |
static void |
main(java.lang.String[] argv)
Demo program for ArgsParser |
void |
parse(java.lang.String[] argv)
Parse the arguments with currently registered options and flags |
java.lang.String |
strValueOf(char sh)
Get value of option sh. |
java.lang.String |
strValueOf(java.lang.String lg)
Get value of option lg. |
java.lang.String |
usage()
Returns usage infomation, to be printed in console or screen. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ArgsParser(java.lang.String program)
program
- The program name, as it will appear in usage informationMethod Detail |
---|
public void addStringOption(char sh, java.lang.String lg, boolean required, java.lang.String defValue, java.lang.String desc) throws lbg.common.io.ArgsParser.OptionException
sh
- The short option character (for -f options), ' ' if nonelg
- The long option string, without first leading '-'. For '--foo'
style options, make only one leading '-', null if nonerequired
- true if the option is requireddefValue
- The default value for that option, null for none. Not
taken into account if option is required.desc
- A description in usage information
OptionException
- In case of option inconsistency
lbg.common.io.ArgsParser.OptionException
public void addListOption(char sh, java.lang.String lg, boolean required, java.lang.String desc) throws lbg.common.io.ArgsParser.OptionException
sh
- The short option character (for -f options), ' ' if nonelg
- The long option string, without first leading '-'. For '--foo'
style options, make only one leading '-', null if nonerequired
- true if the option is requireddesc
- A description in usage information
OptionException
- In case of option inconsistency
lbg.common.io.ArgsParser.OptionException
public void addIntOption(char sh, java.lang.String lg, boolean required, java.lang.Integer defValue, java.lang.String desc) throws lbg.common.io.ArgsParser.OptionException
sh
- The short option character (for -f options), ' ' if nonelg
- The long option string, without first leading '-'. For '--foo'
style options, make only one leading '-', null if nonerequired
- true if the option is requireddefValue
- The default value for that option. Not
taken into account if option is required.desc
- A description in usage information
OptionException
- In case of option inconsistency
lbg.common.io.ArgsParser.OptionException
public void addFlag(char sh, java.lang.String lg, java.lang.String desc) throws lbg.common.io.ArgsParser.OptionException
sh
- The short option character (for -f options), ' ' if nonelg
- The long option string, without first leading '-'. For '--foo'
style options, make only one leading '-', null if nonedesc
- A description in usage information
OptionException
- In case of option inconsistency
lbg.common.io.ArgsParser.OptionException
public void addHelper(char sh, java.lang.String lg, java.lang.String desc) throws lbg.common.io.ArgsParser.OptionException
sh
- The short option character (for -f options), ' ' if nonelg
- The long option string, without first leading '-'. For '--foo'
style options, make only one leading '-', null if nonedesc
- A description in usage information
OptionException
- In case of option inconsistency
lbg.common.io.ArgsParser.OptionException
public void parse(java.lang.String[] argv) throws java.text.ParseException
argv
- The arguments to parse
java.text.ParseException
- if parsing fails. Offset from that exception
is the number of the argumentpublic java.lang.String strValueOf(java.lang.String lg) throws lbg.common.io.ArgsParser.OptionException
lg
- The long option
OptionException
- If the option doesn't exist
lbg.common.io.ArgsParser.OptionException
public java.lang.String strValueOf(char sh) throws lbg.common.io.ArgsParser.OptionException
sh
- The short option
OptionException
- If the option doesn't exist
lbg.common.io.ArgsParser.OptionException
public java.lang.String[] listValueOf(java.lang.String lg) throws lbg.common.io.ArgsParser.OptionException
lg
- The long option
OptionException
- If the option doesn't exist
lbg.common.io.ArgsParser.OptionException
public java.lang.String[] listValueOf(char sh) throws lbg.common.io.ArgsParser.OptionException
sh
- The short option
OptionException
- If the option doesn't exist
lbg.common.io.ArgsParser.OptionException
public int intValueOf(java.lang.String lg) throws lbg.common.io.ArgsParser.OptionException
lg
- The long option
OptionException
- If the option doesn't exist
lbg.common.io.ArgsParser.OptionException
public int intValueOf(char sh) throws lbg.common.io.ArgsParser.OptionException
sh
- The short option
OptionException
- If the option doesn't exist
lbg.common.io.ArgsParser.OptionException
public boolean getFlag(java.lang.String lg) throws lbg.common.io.ArgsParser.OptionException
lg
- The long option
OptionException
- If the option doesn't exist
lbg.common.io.ArgsParser.OptionException
public boolean getFlag(char sh) throws lbg.common.io.ArgsParser.OptionException
sh
- The short option
OptionException
- If the option doesn't exist
lbg.common.io.ArgsParser.OptionException
public java.lang.String usage()
public static void main(java.lang.String[] argv) throws lbg.common.io.ArgsParser.OptionException
lbg.common.io.ArgsParser.OptionException
|
Lightweight Bartering Grid | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Copyright (c) 2005-2008, Cyril Briquet, parts Xavier Dalem.