Parser Module

The class that handles parsing input.

author:

Doug Skrypa

class cli_command_parser.parser.CommandParser(ctx: Context, params: CommandParameters, config: CommandConfig)[source]

Bases: object

Stateful parser used for a single pass of argument parsing

arg_deque: Deque[str] | None
deferred: list[str] | None
ctx
params: CommandParameters
positionals: list[BasePositional]
config: CommandConfig
classmethod parse_args_and_get_next_cmd(ctx: Context) CommandType | None[source]
get_next_cmd(ctx: Context) CommandType | None[source]
handle_pass_thru(ctx: Context) Deque[str][source]
handle_remainder(param: Parameter, value: str) int[source]
handle_positional(arg: str)[source]
handle_long(arg: str)[source]
handle_short(arg: str)[source]
consume_values(param: Parameter, found: int = 0) int[source]

Consume values for the given Parameter.

Parameters:
  • param – The active Parameter that should receive the discovered values

  • found – The number of already discovered values for that Parameter (only specified for positional params)

Returns:

The total number of values that were found for the given Parameter.

cli_command_parser.parser.parse_args_and_get_next_cmd(ctx: Context) CommandType | None
cli_command_parser.parser.get_opt_prefix(text: str) OptStr[source]