rbtools.commands.base.options¶
Command line option management for commands.
Added in version 5.0.
Classes
|
Represents an option for a command. |
|
Represents a named group of options. |
- class rbtools.commands.base.options.Option(*opts: str, added_in: str | None = None, config_key: str | None = None, deprecated_in: str | None = None, extended_help: str | None = None, removed_in: str | None = None, replacement: str | None = None, versions_changed: Mapping[str, str] | None = None, **attrs)[source]¶
Bases:
objectRepresents an option for a command.
This serves as a wrapper around the ArgumentParser options, allowing us to specify additional attributes that are specific to RBTools, such as defaults which will be grabbed from the configuration after it is loaded.
The arguments to the constructor should be treated like those to argparse’s
ArgumentParser.add_argument(), with the exception of the custom arguments that are defined in the constructor.Added in version 6.0: The optional RBTools specific attributes are now stored on the class instead of in
attrs.Added in version 5.0: This is the new location for the old
rbtools.commands.Optionclass.- __firstlineno__ = 19¶
- __init__(*opts: str, added_in: str | None = None, config_key: str | None = None, deprecated_in: str | None = None, extended_help: str | None = None, removed_in: str | None = None, replacement: str | None = None, versions_changed: Mapping[str, str] | None = None, **attrs) None[source]¶
Initialize the option.
Changed in version 6.0: Added explicit arguments for the optional RBTools specific arguments that may be set on an option, pulling them out of
**attrs.- Parameters:
*opts (
tupleofstr) – The long and short form option names.added_in (
str, optional) –The version the option was added in.
Added in version 6.0.
config_key (
str, optional) –A config key to retrieve a default value from RBTools config when the option is not explicitly provided. This will take precedence over any
defaultinattrs.Added in version 6.0.
deprecated_in (
str, optional) –The version the option was deprecated in.
Added in version 6.0.
extended_help (
str, optional) –Extended help message.
Added in version 6.0.
removed_in (
str, optional) –The version in which the option will be removed.
Added in version 6.0.
replacement (
str, optional) –The new option to use instead of the deprecated option, if any.
This should be the longest form name for the option, including any preceding hyphens (e.g.
--my-option).Added in version 6.0.
versions_changed (
dict[str, str], optional) –A dict of versions in which the option changed. The keys are version strings and values are change description strings.
Added in version 6.0.
**attrs (
dict) –The argparse attributes for the option.
These should be valid arguments that can be passed to
ArgumentParser.add_argument().
- __static_attributes__ = ('added_in', 'attrs', 'config_key', 'deprecated_in', 'extended_help', 'opts', 'removed_in', 'replacement', 'versions_changed')¶
- add_to(parent: argparse._ActionsContainer, config: RBToolsConfig | None = None, argv: list[str] | None = None) None[source]¶
Add the option to the parent parser or group.
If the option maps to a configuration key, this will handle figuring out the correct default.
Once we’ve determined the right set of flags, the option will be added to the parser.
- class rbtools.commands.base.options.OptionGroup(name: str | None = None, description: str | None = None, option_list: list[Option] | None = None)[source]¶
Bases:
objectRepresents a named group of options.
Each group has a name, an optional description, and a list of options. It serves as a way to organize related options, making it easier for users to scan for the options they want.
This works like argparse’s argument groups, but is designed to work with our special Option class.
Added in version 5.0: This is the new location for the old
rbtools.commands.OptionGroupclass.- __firstlineno__ = 193¶
- __init__(name: str | None = None, description: str | None = None, option_list: list[Option] | None = None) None[source]¶
Initialize the option group.
- __static_attributes__ = ('description', 'name', 'option_list')¶
- add_to(parser: argparse.ArgumentParser, config: RBToolsConfig, argv: list[str] | None = None) None[source]¶
Add the group and all its contained options to the parser.
- Parameters:
parser (
argparse.ArgumentParser) – The command-line parser.config (
rbtools.config.RBToolsConfig) – The loaded RBTools configuration.argv (
list, deprecated) – Unused legacy argument.