[CommandLine] CLI parsing lib to work with Command
This CL adds two main concepts: ParseableCommand and the CommandParser.
A ParseableCommand is a type of Command (which can be registered with
CommandRegistry for interaction with the SystemUI CLI) that owns a
parser (which is where the main work is done).
CommandParser add the ability to define specific command line tokens:
flags, parameters, and subcommands. Flags are boolean values, defaulting
to false, which when present become true. Parameters are currently
limited to single-arg parameters that have associated value parsers
which can be used to create complex parsed types. Finally, subcomands
are fully-formed commands (with flags and parameters) that can be added
as children to a top-level command. In short:
parser.flag() -> -f, --flag
parser.param() -> -p, --param [args]
parser.subCommand() -> subCommand [fully-formed command]
The returned objects can act as property delegates and handle the
parsing requried to turn the command line string into structured fields
on the command itself, which can then be returned when `execute` is
called.
MyCommand : ParseableCommand() {
val flag by flag(shortName = "f")
val singleParam: Int by param(shortName = "p", Type.Int)
val subCommand: ParseableCommand by subCommand(...)
}
Test: ParseableCommandTest
Test: CommandParserTest
Test: ValueParserTest
Test: ParametersTest
Bug: 288594098
Change-Id: I50c54322b6d640311444169e2850dc8a51aca2ef
Loading
Please register or sign in to comment