public class ParserCLI Parsing Utility.
Usage:
1. Create an Parser Object (with or without prefixes as argument)
2. Register your CLI arguments using Parser.register
3. Give the Parser the String[] args object that you get in your main method
Constructors
public Parser()Will use the default prefix "--"
public Parser(String... prefixes)Constructor with custom prefixes
| Parameters | ||
|---|---|---|
prefixes | String[] | Prefixes that should be used. It's not recommended to use letters or numbers here, since that can mess with the parsing |
Methods
Parser addPrefix(String)Adds a prefix after creation of objectvoid parse(String[])Parses the given arguments and triggers the registered CLI handlers.Parser register(String, String, NoArgCommand)Registers a cli argument.Parser register(String, String, Consumer)Registers a cli argument.Parser register(String, String, TwoArgCommand)Registers a cli argument.Parser register(String, String, ThreeArgCommand)Registers a cli argument.Parser register(String, NoArgCommand)Registers a cli argument.Parser register(String, Consumer)Registers a cli argument.Parser register(String, TwoArgCommand)Registers a cli argument.Parser register(String, ThreeArgCommand)Registers a cli argument.Parser registerVarArgs(String, String, VarArgsCommand)Registers a cli argument.Parser registerVarArgs(String, VarArgsCommand)Registers a cli argument.Parser setDescription(String)Sets Description that will get shown in the help message.Parser setPrefixes(String[])Overwrites prefixes after creation of objectParser setProgram(String)Sets Program "name".public Parser addPrefix(String prefix)public void parse(String[] args)Parses the given arguments and triggers the registered CLI handlers.
| Parameters | ||
|---|---|---|
args | String[] | The raw arguments from your main method |
public Parser register(String arg, String helpText, NoArgCommand handler)Registers a cli argument.
| Parameters | ||
|---|---|---|
arg | String | Argument |
helpText | String | Text to be shown in help |
handler | NoArgCommand | No-arguments callback to be executed once triggered |
| Returns | ||
Parser | Parser object | |
public Parser register(String arg, String helpText, Consumer<String> handler)public Parser register(
String arg,
String helpText,
TwoArgCommand<String, String> handler
)public Parser register(
String arg,
String helpText,
ThreeArgCommand<String, String, String> handler
)public Parser register(String arg, NoArgCommand handler)Registers a cli argument.
| Parameters | ||
|---|---|---|
arg | String | Argument |
handler | NoArgCommand | No-arguments callback to be executed once triggered |
| Returns | ||
Parser | Parser object | |
public Parser register(String arg, Consumer<String> handler)public Parser register(String arg, TwoArgCommand<String, String> handler)Registers a cli argument.
| Parameters | ||
|---|---|---|
arg | String | Argument |
handler | TwoArgCommand<String, String> | Two-arguments callback to be executed once triggered |
| Returns | ||
Parser | Parser object | |
public Parser register(String arg, ThreeArgCommand<String, String, String> handler)public Parser registerVarArgs(String arg, String helpText, VarArgsCommand handler)Registers a cli argument.
| Parameters | ||
|---|---|---|
arg | String | Argument |
helpText | String | Text to be shown in help |
handler | VarArgsCommand | Multi-arguments callback to be executed once triggered |
| Returns | ||
Parser | Parser object | |
public Parser registerVarArgs(String arg, VarArgsCommand handler)Registers a cli argument.
| Parameters | ||
|---|---|---|
arg | String | Argument |
handler | VarArgsCommand | Multi-arguments callback to be executed once triggered |
| Returns | ||
Parser | Parser object | |
public Parser setDescription(String description)public Parser setPrefixes(String... prefixes)public Parser setProgram(String program)