jgdv.cli.parse_machine

Provdes the Main ArgParser_p Protocol, and the ParseMachineBase StateMachine.

ParseMachineBase descibes the state progression to parse arguments, while jgdv.cli.arg_parser.CLIParser adds the specific logic to states and transitions

Classes

ParseMachine

Implemented Parse State Machine

Module Contents

class jgdv.cli.parse_machine.ParseMachine(parser=None, max=MAX_STAGES)[source]

Bases: statemachine.StateMachine

Implemented Parse State Machine

__call__ with: args : list[str] – the cli args to parse (ie: from sys.argv) prog : list[ParamSpec_i] – specs of the top level program cmds : list[ParamSource_p] – commands that can provide their parameters subs : dict[str, list[ParamSource_p]] – a mapping from commands -> subcommands that can provide parameters

A cli call will be of the form: {proghead} {prog [kw]args} {cmd} {cmd[kw]args}* [{subs} {subs[kw]args} [– {subs} {subargs}]* ]? (–help)?

eg: doot -v list -by-group a b c –help doot run basic::task -quick –value=2 –help

Will raise a jgdv.cli.errors.ParseError on failure

Parameters:
on_enter_state(source, event, target) <Unknown>[source]
Parameters:
  • source (statemachine.State)

  • event (statemachine.Event)

  • target (statemachine.State)

Return type:

None

on_exit_state() <Unknown>[source]
Return type:

None

Cleanup
Cmd
End
Head
Help
Kwargs
Posargs
Prepare
Prog
Report
Section
Section_end
Separator
Start
Sub
count = 0
finish
max_attempts = 200
parse
progress
setup