ats_utilities.option.command.command_option module

Module

command_option.py

Copyright

Copyright (C) 2026 Vladimir Roncevic <elektron.ronca@gmail.com> ats_utilities is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. ats_utilities is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

Info

Defines CommandOption used to define command line options.

class ats_utilities.option.command.command_option.CommandOption(name: str, help_text: str, action: str | None = None, default: Any | None = None, required: bool = False, choices: Sequence[Any] | None = None, nargs: str | int | None = None)[source]

Bases: object

Represents metadata for a command line option.

It defines:

attributes:
name - The command line option name.
help_text - Help text for this option.
action - Optional action for this option.
default - Optional default value for this option.
required - True if this option is required.
choices - Optional choices for this option.
nargs - Optional number of arguments for this option.
methods:
validate - Validates that CommandOption instance is valid (can be called after merge).
merge - Merges non-None values from another CommandOption instance into this one.
to_dict - Converts the CommandOption instance to a dictionary.
action: str | None
choices: Sequence[Any] | None
default: Any | None
help_text: str
merge(other: CommandOption) None[source]

Merges non-None values from another CommandOption into this one.

Parameters:

other (<CommandOption>) – Another CommandOption to merge into this one.

Exceptions:
ATSTypeError: Other must be a CommandOption instance.
name: str
nargs: str | int | None
required: bool
to_dict() dict[str, Any][source]

Converts the CommandOption instance to a dictionary.

Returns:

Dictionary representation of the CommandOption instance.

Return type:

<dict[str, Any]>

Exceptions:

None.

validate() None[source]

Validates that CommandOption instance is valid (can be called after merge). Performs validation of name, help_text, action, default, required, choices and nargs attributes. Name must be non-None and a string. Help text must be non-None and a string. Action must be non-None and a string. Default must be non-None. Required must be non-None and a boolean. Choices must be non-None and a sequence. Nargs must be non-None and a string or an integer.

Exceptions:
ATSValueError: Name must be provided.
ATSValueError: Help text must be provided.
ATSValueError: Action must be provided.
ATSValueError: Default must be provided.
ATSValueError: Required must be provided.
ATSTypeError: Required must be a boolean.
ATSValueError: Choices must be provided.
ATSTypeError: Choices must be a sequence.
ATSValueError: Nargs must be provided.
ATSTypeError: Nargs must be a string or an integer.