Groups Module

Parameter Groups

author:

Doug Skrypa

class cli_command_parser.parameters.groups.ParamGroup(name: str = None, *, description: str = None, mutually_exclusive: Bool = False, mutually_dependent: Bool = False, required: Bool = False, hide: Bool = False)[source]

Bases: ParamBase

A group of parameters. Intended to be used as a context manager, where group members are defined inside the with block. Allows arbitrary levels of nesting, including mutually dependent groups inside mutually exclusive groups, and vice versa.

Parameters:
  • name – The name of this group, to appear in help messages.

  • description – A brief description for this group, to appear in help messages.

  • mutually_exclusiveTrue if parameters in this group are mutually exclusive, False otherwise. I.e., if one parameter in this group is provided, then no other parameter in this group will be allowed. Cannot be combined with mutually_dependent.

  • mutually_dependentTrue if parameters in this group are mutually dependent, False otherwise. I.e., if one parameter in this group is provided, then all other parameters in this group must also be provided. Cannot be combined with mutually_exclusive.

  • required – Whether at least one parameter in this group is required or not. If it is required, then an exception will be raised if the user did not provide a value for any parameters in this group. Defaults to False.

  • hide – If True, this group of parameters will not be included in usage / help messages. Defaults to False.

description: str | None
members: list[ParamOrGroup]
mutually_exclusive: Bool = False
mutually_dependent: Bool = False
add(param: ParamOrGroup)[source]

Add the given parameter without storing a back-reference. Primary use case is for help text only groups.

extend(params: Iterable[ParamOrGroup])[source]

Add the given parameters without storing a back-reference. Primary use case is for help text only groups.

register(param: ParamOrGroup)[source]
register_all(params: Iterable[ParamOrGroup])[source]
property in_mutually_exclusive_group: bool[source]
validate()[source]

Validate mutual dependency / exclusivity of members and that required members have been provided when they are expected to be (based on mutual dependence/exclusivity and nesting).

This method is called during parsing, after initially parsing arguments, before evaluating whether a subcommand choice was provided. Groups are validated in order, starting from the inner-most groups and working outward so that nested groups are validated before any group that they are a member of.

property contains_positional: bool[source]
property contains_required: bool[source]
property show_in_help: bool[source]