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_exclusive¶ –
True
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 withmutually_dependent
.mutually_dependent¶ –
True
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 withmutually_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 toFalse
.
- 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.
- 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.