classinternalSource
public class Parser

CLI 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
prefixesString[]Prefixes that should be used. It's not recommended to use letters or numbers here, since that can mess with the parsing

Methods

public Parser addPrefix(String prefix)
Adds a prefix after creation of object
Parameters
prefixStringPrefix to be added
Returns
ParserParser object
public void parse(String[] args)
Parses the given arguments and triggers the registered CLI handlers.
Parameters
argsString[]The raw arguments from your main method
public Parser register(String arg, String helpText, NoArgCommand handler)
Registers a cli argument.
Parameters
argStringArgument
helpTextStringText to be shown in help
handlerNoArgCommandNo-arguments callback to be executed once triggered
Returns
ParserParser object
public Parser register(String arg, String helpText, Consumer<String> handler)
Registers a cli argument.
Parameters
argStringArgument
helpTextStringText to be shown in help
handlerConsumer<String>Single-argument callback to be executed once triggered
Returns
ParserParser object
public Parser register(
    String arg,
    String helpText,
    TwoArgCommand<String, String> handler
)
Registers a cli argument.
Parameters
argStringArgument
helpTextStringText to be shown in help
handlerTwoArgCommand<String, String>Two-arguments callback to be executed once triggered
Returns
ParserParser object
public Parser register(
    String arg,
    String helpText,
    ThreeArgCommand<String, String, String> handler
)
Registers a cli argument.
Parameters
argStringArgument
helpTextStringText to be shown in help
handlerThreeArgCommand<String, String, String>Three-arguments callback to be executed once triggered
Returns
ParserParser object
public Parser register(String arg, NoArgCommand handler)
Registers a cli argument.
Parameters
argStringArgument
handlerNoArgCommandNo-arguments callback to be executed once triggered
Returns
ParserParser object
public Parser register(String arg, Consumer<String> handler)
Registers a cli argument.
Parameters
argStringArgument
handlerConsumer<String>Single-argument callback to be executed once triggered
Returns
ParserParser object
public Parser register(String arg, TwoArgCommand<String, String> handler)
Registers a cli argument.
Parameters
argStringArgument
handlerTwoArgCommand<String, String>Two-arguments callback to be executed once triggered
Returns
ParserParser object
public Parser register(String arg, ThreeArgCommand<String, String, String> handler)
Registers a cli argument.
Parameters
argStringArgument
handlerThreeArgCommand<String, String, String>Three-arguments callback to be executed once triggered
Returns
ParserParser object
public Parser registerVarArgs(String arg, String helpText, VarArgsCommand handler)
Registers a cli argument.
Parameters
argStringArgument
helpTextStringText to be shown in help
handlerVarArgsCommandMulti-arguments callback to be executed once triggered
Returns
ParserParser object
public Parser registerVarArgs(String arg, VarArgsCommand handler)
Registers a cli argument.
Parameters
argStringArgument
handlerVarArgsCommandMulti-arguments callback to be executed once triggered
Returns
ParserParser object
public Parser setDescription(String description)
Sets Description that will get shown in the help message.
Parameters
descriptionStringDescription to be shown
Returns
ParserParser object
public Parser setPrefixes(String... prefixes)
Overwrites prefixes after creation of object
Parameters
prefixesString[]Updated prefixes list
Returns
ParserParser object
public Parser setProgram(String program)
Sets Program "name". Will get shown in the help message. This should be the command used to launch the program, so either the direct name if registered in the command line or the path to the executable.
Parameters
programStringProgram name or path
Returns
ParserParser object

Nested types