Package ortus.boxlang.runtime.util
Class CLIUtil
java.lang.Object
ortus.boxlang.runtime.util.CLIUtil
A collection of utility methods for the CLI.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic IStructparseArguments(String[] args) Parse the cli arguments into a struct of options and positional argumentsstatic IStructparseArguments(List<String> args) Quick parser for options on cli arguments for BoxLang
-
Constructor Details
-
CLIUtil
public CLIUtil()
-
-
Method Details
-
parseArguments
Parse the cli arguments into a struct of options and positional arguments- Parameters:
args- The cli arguments as an array- Returns:
- A struct of the options and positional arguments
-
parseArguments
Quick parser for options on cli arguments for BoxLangThis method will parse the cli arguments and return a struct of the following:
options- A struct of the optionspositionals- An array of the positional arguments
The options can be provided in the following formats:
--option- A boolean option--option=value- An option with a value--option="value"- An option with a quoted value--option='value'- An option with a quoted value-o=value- A shorthand option with a value-o- A shorthand boolean option--!option- A negation option
For example, the following cli arguments:
--debug --!verbose --bundles=Spec -o='/path/to/file' -v my/path/template
Will be parsed into the following struct:
{ "options" : { "debug": true, "verbose": false, "bundles": "Spec", "o": "/path/to/file", "v": true }, "positionals": [ "my/path/template" ]Some Ground Rules
- Options are prefixed with --
- Shorthand options are prefixed with -
- Options can be negated with --! or --no-
- Options can have values separated by =
- Values can be quoted with single or double quotes
- Repeated options will override the previous value
- Returns:
- A struct of the options and positional arguments
-