|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.Ostermiller.util.CmdLn
public final class CmdLn
Command line argument parser for Java command line programs. More information about this class and code samples for suggested use are available from ostermiller.org.
| Constructor Summary | |
|---|---|
CmdLn(java.lang.String[] arguments)
New command line options with the given command line arguments |
|
| Method Summary | |
|---|---|
CmdLn |
addOption(CmdLnOption option)
Add option. |
CmdLn |
addOptions(CmdLnOption[] options)
Add options. |
CmdLn |
addOptions(java.util.Collection<CmdLnOption> options)
Add options. |
java.lang.String |
getHelp()
Print help for the command line options. |
java.lang.String |
getHelp(int indent,
int width)
Print help for the command line options. |
java.util.List<java.lang.String> |
getNonOptionArguments()
Get the left over arguments -- the arguments that are not associated with any arguments. |
CmdLnResult |
getResult(char c)
Get the last result associated with the given argument. |
CmdLnResult |
getResult(java.lang.Character c)
Get the last result associated with the given argument. |
CmdLnResult |
getResult(CmdLnOption option)
Get the last result associated with the option. |
CmdLnResult |
getResult(java.lang.String s)
Get the last result associated with the given argument. |
java.util.List<CmdLnResult> |
getResults()
Get all the results in the order in which they appear in the command line. |
java.util.List<CmdLnResult> |
getResults(char c)
Get all the results associated with the given argument in the order in which they appear in the command line. |
java.util.List<CmdLnResult> |
getResults(java.lang.Character c)
Get all the results associated with the given argument in the order in which they appear in the command line. |
java.util.List<CmdLnResult> |
getResults(CmdLnOption option)
Get all the results associated with the given argument in the order in which they appear in the command line. |
java.util.List<CmdLnResult> |
getResults(java.lang.String s)
Get all the results associated with the given argument in the order in which they appear in the command line. |
int |
occurrences(char c)
The number of times the specified option is present in the command line. |
int |
occurrences(java.lang.Character c)
The number of times the specified option is present in the command line. |
int |
occurrences(CmdLnOption option)
The number of times the specified option is present in the command line. |
int |
occurrences(java.lang.String s)
The number of times the specified option is present in the command line. |
void |
parse()
Parse the command line options if they have not already been parsed. |
boolean |
present(char c)
Whether or not the specified option is present in the command line. |
boolean |
present(java.lang.Character c)
Whether or not the specified option is present in the command line. |
boolean |
present(CmdLnOption option)
Whether or not the specified option is present in the command line. |
boolean |
present(java.lang.String s)
Whether or not the specified option is present in the command line. |
void |
printHelp()
Print help for the command line options to standard output. |
void |
printHelp(int indent,
int width)
Print help for the command line options to standard output. |
void |
printHelp(java.io.OutputStream out)
Print help for the command line options. |
void |
printHelp(java.io.OutputStream out,
int indent,
int width)
Print help for the command line options. |
void |
printHelp(java.io.PrintWriter out)
Print help for the command line options. |
void |
printHelp(java.io.PrintWriter out,
int indent,
int width)
Print help for the command line options. |
void |
printHelp(java.io.Writer out)
Print help for the command line options. |
void |
printHelp(java.io.Writer out,
int indent,
int width)
Print help for the command line options. |
CmdLn |
setDescription(java.lang.String description)
Set the description for the program. |
CmdLn |
setNonOptionSeparators(java.lang.String[] nonOptionSeparators)
Set the "stop" option that causes any following arguments to be treated as non-option arguments, even if they look like an option. |
CmdLn |
setOptionArgumentDelimiters(char[] delimiters)
Set the delimiters that separate a option name from a value within a single argument. |
CmdLn |
setOptionStarts(java.lang.String[] longOptionsStart,
java.lang.String[] shortOptionsStart)
Set what long options and short options start with. |
CmdLn |
setOptionStarts(java.lang.String longOptionsStart,
java.lang.String shortOptionsStart)
Set what long options and short options start with. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public CmdLn(java.lang.String[] arguments)
arguments - command line arguments from main method| Method Detail |
|---|
public CmdLn setOptionArgumentDelimiters(char[] delimiters)
delimiters - list of delimiters
public CmdLn setOptionStarts(java.lang.String longOptionsStart,
java.lang.String shortOptionsStart)
longOptionsStart - What long options start with (default "--") or null for no long options;shortOptionsStart - What short options start with (default "-") or null for no short options;
java.lang.IllegalArgumentException - if the long or short start is the empty string
public CmdLn setOptionStarts(java.lang.String[] longOptionsStart,
java.lang.String[] shortOptionsStart)
The first option start in each array will be the canonical option start that is used in the help message.
longOptionsStart - What long options start with (default "--") or null or empty for no long options;shortOptionsStart - What short options start with (default "-") or null or empty for no short options;
java.lang.IllegalArgumentException - if the long or short start is the empty stringpublic CmdLn setNonOptionSeparators(java.lang.String[] nonOptionSeparators)
The default non-option separator is "--".
nonOptionSeparators - List of arguments that stop processing options and treat remaining arguments as non option arguments.
public CmdLn setDescription(java.lang.String description)
description - short description about the program
public CmdLn addOptions(java.util.Collection<CmdLnOption> options)
options - options to be added.
java.lang.NullPointerException - if the options are null.
java.lang.NullPointerException - if any option in the collection is null.
java.lang.IllegalStateException - if the command line has already been parsed.public CmdLn addOptions(CmdLnOption[] options)
options - options to be added.
java.lang.NullPointerException - if the options are null.
java.lang.NullPointerException - if any option in the collection is null.
java.lang.IllegalStateException - if the command line has already been parsed.public CmdLn addOption(CmdLnOption option)
option - option to be added.
java.lang.NullPointerException - if the option is null.
java.lang.IllegalStateException - if the command line has already been parsed.public CmdLnResult getResult(java.lang.String s)
s - long argument
UnknownCmdLnOptionException - if an unexpected option is encountered during parsing.
MissingCmdLnArgumentException - if a command line option does not have enough arguments during parsing.
ExtraCmdLnArgumentException - if a command line option has too many arguments during parsing.public CmdLnResult getResult(java.lang.Character c)
c - short argument
UnknownCmdLnOptionException - if an unexpected option is encountered during parsing.
MissingCmdLnArgumentException - if a command line option does not have enough arguments during parsing.
ExtraCmdLnArgumentException - if a command line option has too many arguments during parsing.public CmdLnResult getResult(char c)
c - short argument
UnknownCmdLnOptionException - if an unexpected option is encountered during parsing.
MissingCmdLnArgumentException - if a command line option does not have enough arguments during parsing.
ExtraCmdLnArgumentException - if a command line option has too many arguments during parsing.public CmdLnResult getResult(CmdLnOption option)
option - command line option
UnknownCmdLnOptionException - if an unexpected option is encountered during parsing.
MissingCmdLnArgumentException - if a command line option does not have enough arguments during parsing.
ExtraCmdLnArgumentException - if a command line option has too many arguments during parsing.public java.util.List<CmdLnResult> getResults()
UnknownCmdLnOptionException - if an unexpected option is encountered during parsing.
MissingCmdLnArgumentException - if a command line option does not have enough arguments during parsing.
ExtraCmdLnArgumentException - if a command line option has too many arguments during parsing.public java.util.List<CmdLnResult> getResults(java.lang.String s)
s - long argument
UnknownCmdLnOptionException - if an unexpected option is encountered during parsing.
MissingCmdLnArgumentException - if a command line option does not have enough arguments during parsing.
ExtraCmdLnArgumentException - if a command line option has too many arguments during parsing.public java.util.List<CmdLnResult> getResults(java.lang.Character c)
c - short argument
UnknownCmdLnOptionException - if an unexpected option is encountered during parsing.
MissingCmdLnArgumentException - if a command line option does not have enough arguments during parsing.public java.util.List<CmdLnResult> getResults(char c)
c - short argument
UnknownCmdLnOptionException - if an unexpected option is encountered during parsing.
MissingCmdLnArgumentException - if a command line option does not have enough arguments during parsing.
ExtraCmdLnArgumentException - if a command line option has too many arguments during parsing.public java.util.List<CmdLnResult> getResults(CmdLnOption option)
option - command line option
UnknownCmdLnOptionException - if an unexpected option is encountered during parsing.
MissingCmdLnArgumentException - if a command line option does not have enough arguments during parsing.
ExtraCmdLnArgumentException - if a command line option has too many arguments during parsing.public boolean present(java.lang.String s)
s - long argument
UnknownCmdLnOptionException - if an unexpected option is encountered during parsing.
MissingCmdLnArgumentException - if a command line option does not have enough arguments during parsing.
ExtraCmdLnArgumentException - if a command line option has too many arguments during parsing.public boolean present(java.lang.Character c)
c - short argument
UnknownCmdLnOptionException - if an unexpected option is encountered during parsing.
MissingCmdLnArgumentException - if a command line option does not have enough arguments during parsing.
ExtraCmdLnArgumentException - if a command line option has too many arguments during parsing.public boolean present(char c)
c - short argument
UnknownCmdLnOptionException - if an unexpected option is encountered during parsing.
MissingCmdLnArgumentException - if a command line option does not have enough arguments during parsing.
ExtraCmdLnArgumentException - if a command line option has too many arguments during parsing.public boolean present(CmdLnOption option)
option - command line option
UnknownCmdLnOptionException - if an unexpected option is encountered during parsing.
MissingCmdLnArgumentException - if a command line option does not have enough arguments during parsing.
ExtraCmdLnArgumentException - if a command line option has too many arguments during parsing.public int occurrences(java.lang.String s)
s - long argument
UnknownCmdLnOptionException - if an unexpected option is encountered during parsing.
MissingCmdLnArgumentException - if a command line option does not have enough arguments during parsing.
ExtraCmdLnArgumentException - if a command line option has too many arguments during parsing.public int occurrences(java.lang.Character c)
c - short argument
UnknownCmdLnOptionException - if an unexpected option is encountered during parsing.
MissingCmdLnArgumentException - if a command line option does not have enough arguments during parsing.
ExtraCmdLnArgumentException - if a command line option has too many arguments during parsing.public int occurrences(char c)
c - short argument
UnknownCmdLnOptionException - if an unexpected option is encountered during parsing.
MissingCmdLnArgumentException - if a command line option does not have enough arguments during parsing.
ExtraCmdLnArgumentException - if a command line option has too many arguments during parsing.public int occurrences(CmdLnOption option)
option - command line option
UnknownCmdLnOptionException - if an unexpected option is encountered during parsing.
MissingCmdLnArgumentException - if a command line option does not have enough arguments during parsing.
ExtraCmdLnArgumentException - if a command line option has too many arguments during parsing.public java.util.List<java.lang.String> getNonOptionArguments()
UnknownCmdLnOptionException - if an unexpected option is encountered during parsing.
MissingCmdLnArgumentException - if a command line option does not have enough arguments during parsing.
ExtraCmdLnArgumentException - if a command line option has too many arguments during parsing.public void parse()
Once this command line has been parsed, options may no longer be added.
UnknownCmdLnOptionException - if an unexpected option is encountered
MissingCmdLnArgumentException - if a command line option does not have enough arguments.
ExtraCmdLnArgumentException - if a command line option has too many arguments.public java.lang.String getHelp()
program description --argument -a > argument a description --another -b argument b description --third -c > argument c descriptionIndentation is the default twenty, and line width is the default 80. Parses the command line if not already parsed.
UnknownCmdLnOptionException - if an unexpected option is encountered during parsing.
MissingCmdLnArgumentException - if a command line option does not have enough arguments during parsing.public void printHelp()
program description --argument -a > argument a description --another -b argument b description --third -c > argument c descriptionIndentation is the default twenty, and line width is the default eighty. Parses the command line if not already parsed.
UnknownCmdLnOptionException - if an unexpected option is encountered during parsing.
MissingCmdLnArgumentException - if a command line option does not have enough arguments during parsing.public void printHelp(java.io.OutputStream out)
out - destination to which the help is written.
UnknownCmdLnOptionException - if an unexpected option is encountered during parsing.
MissingCmdLnArgumentException - if a command line option does not have enough arguments during parsing.public void printHelp(java.io.Writer out)
program description --argument -a > argument a description --another -b argument b description --third -c > argument c descriptionIndentation is the default twenty, and line width is the default eighty. Parses the command line if not already parsed.
out - destination to which the help is written.
UnknownCmdLnOptionException - if an unexpected option is encountered during parsing.
MissingCmdLnArgumentException - if a command line option does not have enough arguments during parsing.public void printHelp(java.io.PrintWriter out)
program description --argument -a > argument a description --another -b argument b description --third -c > argument c descriptionIndentation is the default twenty, and line width is the default eighty. Parses the command line if not already parsed.
out - destination to which the help is written.
UnknownCmdLnOptionException - if an unexpected option is encountered during parsing.
MissingCmdLnArgumentException - if a command line option does not have enough arguments during parsing.
public java.lang.String getHelp(int indent,
int width)
program description --argument -a > argument a description --another -b argument b description --third -c > argument c descriptionParses the command line if not already parsed.
indent - the maximum number of characters to which all descriptions should be indented.width - the number of characters at which text should be wrapped.
UnknownCmdLnOptionException - if an unexpected option is encountered during parsing.
MissingCmdLnArgumentException - if a command line option does not have enough arguments during parsing.
public void printHelp(int indent,
int width)
program description --argument -a > argument a description --another -b argument b description --third -c > argument c descriptionParses the command line if not already parsed.
indent - the maximum number of characters to which all descriptions should be indented.width - the number of characters at which text should be wrapped.
UnknownCmdLnOptionException - if an unexpected option is encountered during parsing.
MissingCmdLnArgumentException - if a command line option does not have enough arguments during parsing.
public void printHelp(java.io.OutputStream out,
int indent,
int width)
program description --argument -a > argument a description --another -b argument b description --third -c > argument c descriptionParses the command line if not already parsed.
out - destination to which the help is written.indent - the maximum number of characters to which all descriptions should be indented.width - the number of characters at which text should be wrapped.
UnknownCmdLnOptionException - if an unexpected option is encountered during parsing.
MissingCmdLnArgumentException - if a command line option does not have enough arguments during parsing.
public void printHelp(java.io.Writer out,
int indent,
int width)
program description --argument -a > argument a description --another -b argument b description --third -c > argument c descriptionParses the command line if not already parsed.
out - destination to which the help is written.indent - the maximum number of characters to which all descriptions should be indented.width - the number of characters at which text should be wrapped.
UnknownCmdLnOptionException - if an unexpected option is encountered during parsing.
MissingCmdLnArgumentException - if a command line option does not have enough arguments during parsing.
public void printHelp(java.io.PrintWriter out,
int indent,
int width)
program description --argument -a > argument a description --another -b argument b description --third -c > argument c descriptionParses the command line if not already parsed.
out - destination to which the help is written.indent - the maximum number of characters to which all descriptions should be indented.width - the number of characters at which text should be wrapped.
UnknownCmdLnOptionException - if an unexpected option is encountered during parsing.
MissingCmdLnArgumentException - if a command line option does not have enough arguments during parsing.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||