|
com.Ostermiller.util Java Utilities |
|||||||
| 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(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(Collection<CmdLnOption> options)
Add options. |
String |
getHelp()
Print help for the command line options. |
String |
getHelp(int indent,
int width)
Print help for the command line options. |
List<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(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(String s)
Get the last result associated with the given argument. |
List<CmdLnResult> |
getResults()
Get all the results in the order in which they appear in the command line. |
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. |
List<CmdLnResult> |
getResults(Character c)
Get all the results associated with the given argument in the order in which they appear in the command line. |
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. |
List<CmdLnResult> |
getResults(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(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(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(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(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(OutputStream out)
Print help for the command line options. |
void |
printHelp(OutputStream out,
int indent,
int width)
Print help for the command line options. |
void |
printHelp(PrintWriter out)
Print help for the command line options. |
void |
printHelp(PrintWriter out,
int indent,
int width)
Print help for the command line options. |
void |
printHelp(Writer out)
Print help for the command line options. |
void |
printHelp(Writer out,
int indent,
int width)
Print help for the command line options. |
CmdLn |
setDescription(String description)
Set the description for the program. |
CmdLn |
setNonOptionSeparators(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(String[] longOptionsStart,
String[] shortOptionsStart)
Set what long options and short options start with. |
CmdLn |
setOptionStarts(String longOptionsStart,
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(String[] arguments)
arguments - command line arguments from main method| Method Detail |
|---|
public CmdLn setOptionArgumentDelimiters(char[] delimiters)
delimiters - list of delimiters
public CmdLn setOptionStarts(String longOptionsStart,
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;
IllegalArgumentException - if the long or short start is the empty string
public CmdLn setOptionStarts(String[] longOptionsStart,
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;
IllegalArgumentException - if the long or short start is the empty stringpublic CmdLn setNonOptionSeparators(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(String description)
description - short description about the program
public CmdLn addOptions(Collection<CmdLnOption> options)
options - options to be added.
NullPointerException - if the options are null.
NullPointerException - if any option in the collection is null.
IllegalStateException - if the command line has already been parsed.public CmdLn addOptions(CmdLnOption[] options)
options - options to be added.
NullPointerException - if the options are null.
NullPointerException - if any option in the collection is null.
IllegalStateException - if the command line has already been parsed.public CmdLn addOption(CmdLnOption option)
option - option to be added.
NullPointerException - if the option is null.
IllegalStateException - if the command line has already been parsed.public CmdLnResult getResult(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(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 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 List<CmdLnResult> getResults(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 List<CmdLnResult> getResults(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 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 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(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(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(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(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 List<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 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(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(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(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 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(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(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(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.
|
com.Ostermiller.util Java Utilities |
|||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
Copyright (c) 2001-2007 by Stephen Ostermiller