Arguments#
The Arguments module provides classes for working with command-line arguments. They allow configuring application behavior at startup by passing various configuration parameters.
Arguments are registered in ArgParser and after processing become available in the ArgSpace object.
ValueArgument#
Class for arguments that require passing a value.
- class ValueArgument(BaseArgument)
1__init__(self, name: str, *,
2 prefix: Literal["-", "--", "---"] = "--",
3 help: str = "Help message for the value argument",
4 possible_values: list[str] | None = None,
5 default: str | None = None,
6 is_required: bool = False,
7 is_deprecated: bool = False) -> None
Creates a command-line argument that requires a value.
- param name:
Argument name
- param prefix:
Prefix (defaults to
--)- param help:
Help message (
--help)- param possible_values:
List of allowed values
- param default:
Default value if the argument is not passed
- param is_required:
If
True, the argument becomes required. If not passed at startup, the application will not start- param is_deprecated:
If
True, marks the argument as deprecated. If passed at startup, a warning will be displayed in the console
Usage example:
1from argenta.orchestrator.argparser import ArgParser, ValueArgument
2
3# Create arguments
4config_arg = ValueArgument("config", help="Path to configuration file", default="config.yaml")
5
6log_level_arg = ValueArgument(
7 "log-level",
8 help="Logging level",
9 possible_values=["DEBUG", "INFO", "WARNING", "ERROR"],
10 default="INFO",
11)
12
13host_arg = ValueArgument("host", help="Server host address", is_required=True)
14
15# Register in ArgParser
16parser = ArgParser(
17 processed_args=[config_arg, log_level_arg, host_arg],
18 name="MyApp",
19 description="My application with CLI arguments",
20)
Running the application:
python app.py --host 127.0.0.1
python app.py --host 127.0.0.1 --config custom.yaml --log-level DEBUG
BooleanArgument#
Class for boolean arguments that do not require a value. Their presence at startup sets the value to True, absence to False.
- class BooleanArgument(BaseArgument)
1__init__(self, name: str, *,
2 prefix: Literal["-", "--", "---"] = "--",
3 help: str = "Help message for the boolean argument",
4 is_deprecated: bool = False) -> None
Creates a boolean command-line argument without a value.
- param name:
Argument name
- param prefix:
Prefix (defaults to
--)- param help:
Help message (
--help)- param is_deprecated:
If
True, marks the argument as deprecated
Usage example:
1from argenta.orchestrator.argparser import ArgParser, BooleanArgument
2
3# Create boolean arguments
4verbose_arg = BooleanArgument("verbose", help="Enable verbose output")
5debug_arg = BooleanArgument("debug", help="Enable debug mode")
6no_cache_arg = BooleanArgument("no-cache", help="Disable caching")
7
8# Register in ArgParser
9parser = ArgParser(processed_args=[verbose_arg, debug_arg, no_cache_arg], name="MyApp")
Running the application:
python app.py --verbose
python app.py --debug --no-cache
python app.py # without arguments
InputArgument#
See also
InputArgument is directly related to the ArgSpace container and serves as its filler. For more details, see here.
Represents a processed command-line argument. This class is used inside ArgSpace to store values obtained after parsing.
- class InputArgument
1__init__(self, name: str,
2 value: str | Literal[True],
3 founder_class: type[BaseArgument]) -> None
Creates an instance of a processed input argument.
- param name:
Argument name
- param value:
Argument value. For
BooleanArgument— True if the argument is passed, and False if not; forValueArgument— the entered string- param founder_class:
Parent class from which the argument was created (
BooleanArgumentorValueArgument)
Attributes:
- name
Argument name specified when creating
ValueArgumentorBooleanArgument.
- value#
Argument value. Type depends on the source class:
For
BooleanArgument: True if the argument was passedFor
ValueArgument: string with the passed value or default value
- founder_class#
Reference to the parent class. Used for type determination and filtering.