jgdv.cli._interface

Enums

SectionType_e

The different types of section a parse machine can process

Protocols

ArgParserModel_p

The Model used in a jgdv.cli.arg_parser:ParseMachine to implement specific parsing logic

AssignmentParam_p

Interface to mark a parameter as an assignment

CLIParamProvider_p

Things that can provide parameter specs for CLI parsing

KeyParam_p

Interface to mark a parameter as a key value pair

ParamSource_p

Param Sources are anything that can provide a name and a set of parameters

ParamSpec_i

Base class for CLI param specs, for type matching

ParamSpec_p

Base class for CLI param specs, for type matching

PositionalParam_p

Interface to mark a parameter as positional

ToggleParam_p

Interface to mark a parameter as a boolean toggle

Classes

ParseReport_d

The returned data of parsing cli args

ParseResult_d

Simple container for parsed cli information

Module Contents

class jgdv.cli._interface.SectionType_e(*args, **kwds)[source]

Bases: enum.Enum

The different types of section a parse machine can process

cmd
prog
sub
class jgdv.cli._interface.ArgParserModel_p[source]

Bases: Protocol

The Model used in a jgdv.cli.arg_parser:ParseMachine to implement specific parsing logic

prepare_for_parse(
*,
prog,
cmds,
subs,
raw_args,
) <Unknown>[source]
Parameters:
Return type:

None

class jgdv.cli._interface.AssignmentParam_p[source]

Bases: Protocol

Interface to mark a parameter as an assignment

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

Literal[True]

class jgdv.cli._interface.CLIParamProvider_p[source]

Bases: Protocol

Things that can provide parameter specs for CLI parsing

classmethod param_specs() <Unknown>[source]

make class parameter specs

Return type:

list[ParamSpec_i]

class jgdv.cli._interface.KeyParam_p[source]

Bases: Protocol

Interface to mark a parameter as a key value pair

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

Literal[True]

class jgdv.cli._interface.ParamSource_p[source]

Bases: Protocol

Param Sources are anything that can provide a name and a set of parameters

abstractmethod param_specs() <Unknown>[source]
Return type:

list[ParamSpec_i]

property name: str[source]
Abstractmethod:

Return type:

str

class jgdv.cli._interface.ParamSpec_i[source]

Bases: ParamSpec_p, Protocol

Base class for CLI param specs, for type matching when ‘consume’ is given a list of strs, it can match on the args, and return an updated diction and a list of values it didn’t consume

_processor: ClassVar
count: int
default: Any | collections.abc.Callable
desc: str
implicit: bool
insist: bool
name: str
prefix: int | str
separator: str | Literal[False]
type_: jgdv.Maybe[type]
class jgdv.cli._interface.ParamSpec_p[source]

Bases: Protocol

Base class for CLI param specs, for type matching when ‘consume’ is given a list of strs, it can match on the args, and return an updated diction and a list of values it didn’t consume

consume(args, *, offset=0) <Unknown>[source]
Parameters:
Return type:

jgdv.Maybe[tuple[dict, int]]

help_str(*, force=False) <Unknown>[source]
Parameters:

force (bool)

Return type:

str

classmethod key_func(x) <Unknown>[source]
Parameters:

x (ParamSpec_i)

Return type:

tuple

property default_tuple: tuple[str, Any][source]
Return type:

tuple[str, Any]

property default_value: Any[source]
Return type:

Any

property inverse: str[source]
Return type:

str

property key_str: str[source]
Return type:

str

property key_strs: list[str][source]
Return type:

list[str]

property repeatable: bool[source]
Return type:

bool

property short: str[source]
Return type:

str

property short_key_str: jgdv.Maybe[str][source]
Return type:

jgdv.Maybe[str]

class jgdv.cli._interface.PositionalParam_p[source]

Bases: Protocol

Interface to mark a parameter as positional

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

Literal[True]

class jgdv.cli._interface.ToggleParam_p[source]

Bases: Protocol

Interface to mark a parameter as a boolean toggle

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

Literal[True]

class jgdv.cli._interface.ParseReport_d(*, raw, remaining, prog, _help)[source]

The returned data of parsing cli args

Parameters:
to_dict() <Unknown>[source]
Return type:

dict

CmdName: TypeAlias = str
SubName: TypeAlias = str
cmds: dict[ParseReport_d.CmdName, tuple[ParseResult_d]]
help: bool
prog: ParseResult_d
raw: tuple[str, Ellipsis]
remaining: tuple[str, Ellipsis]
subs: dict[ParseReport_d.SubName, tuple[ParseResult_d]]
class jgdv.cli._interface.ParseResult_d(name, args=None, ref=None)[source]

Simple container for parsed cli information

Parameters:
  • name (str) – the name of the spec that parsed this data

  • args (jgdv.Maybe[dict]) – mapping of {arg -> data}, including default values it nothing parsing for it

  • non_default – set[arg, …] that actually parsed

  • ref (jgdv.Maybe[str]) – the name of a linked parse result this object extends

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

dict

args: dict
name: str
non_default: set[str]
ref: jgdv.Maybe[str]