Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Skip to content
Commit 02e51494 authored by Evan Laird's avatar Evan Laird
Browse files

[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
parent b1aa9460
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment