ats_utilities.option.iparser_strategy module

Module

iparser_strategy.py

Copyright

Copyright (C) 2017 - 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 abstract class IParserStrategy with method(s). Creates an interface for ATS option parsing.

class ats_utilities.option.iparser_strategy.IParserStrategy[source]

Bases: ABC

Defines abstract class IParserStrategy with method(s). Interface for concrete parsing engines (Strategy Pattern). Allows third-party parsers to be injected from the outside.

It defines:

attributes:

None

methods:
setup - Initializes the underlying parser with metadata parameters.
add_argument - Adds an operational argument/flag to the parser.
add_version - Adds a version display option to the parser.
parse - Parses the input arguments and returns an OptionNamespace.
register_commands - Registers a list of commands with the parser.
parse_command - Parses the input arguments and returns an OptionNamespace.
ok - Checks if parser strategy component is ok.
__str__ - Returns the ATS parser strategy as string representation.
_abc_impl = <_abc._abc_data object>
abstractmethod add_argument(*args: str, **kwargs: Any) None[source]

Adds an operational argument/flag to the parser.

Parameters:
  • args (<str>) – Arguments in string format.

  • kwargs (<Any>) – Arguments in Any form

Exceptions:

NotImplementedError.

abstractmethod add_version(version: str | None) None[source]

Adds a version display option to the parser.

Parameters:

version (<str | None>) – The ATS version in string format | None.

Exceptions:

NotImplementedError.

abstractmethod is_initialized() bool[source]

Checks if parser strategy component is ok.

Returns:

True (success) | False (fail).

Return type:

<bool>

Exceptions:

NotImplementedError.

abstractmethod parse(arguments: Sequence[str] | None, known_only: bool = False) OptionNamespace[source]

Parses the input arguments and returns an OptionNamespace.

Parameters:
  • arguments (<OptArgs>) – Sequence of arguments | None.

  • known_only (<bool>) – Parse only known arguments.

Returns:

Option namespace object.

Return type:

<OptionNamespace>

Exceptions:

NotImplementedError.

abstractmethod parse_command(arguments: Sequence[str] | None = None) tuple[str, dict][source]

Parses CLI arguments for subcommands and returns command name and parameters.

Parameters:

arguments (<OptArgs>) – Sequence of arguments | None.

Returns:

Tuple containing command name and parsed parameters.

Return type:

<tuple[str, dict]>

Exceptions:

NotImplementedError.

abstractmethod register_commands(commands: list[IOptionCommand]) None[source]

Register a list of commands with the parser.

Parameters:

commands (<list[IOptionCommand]>) – List of commands to register.

Exceptions:

NotImplementedError.

abstractmethod setup(parameters: dict[str, str]) None[source]

Initializes the underlying parser with metadata parameters.

Parameters:

parameters (<dict[str, str]>) – Parameters for logger in dict format.

Exceptions:

NotImplementedError.