get_args¶
Overview¶
The get_args application demonstrates how to handle command-line arguments in a Raya application. It requires a mandatory argument and allows an optional default argument.
Inputs¶
Mandatory Argument (`-m` or `–mandatory-arg`): Required argument that must be provided when executing the script.
Optional Default Argument (`-d` or `–default-arg`): Can be provided, but if omitted, it defaults to “default_value”.
Outputs¶
Log messages displaying the values of the provided arguments.
A loop that prints five log messages before the application exits.
Execution¶
To execute the application, use:
Running without required arguments (will fail):
python3 get_args/ --auto-run
This will produce an error message:
usage: [-h] [--verbose-error] ... -m MANDATORY_ARG error: the following arguments are required: -m/--mandatory-arg [CRITICAL] [timestamp] [RayaApp.EntryPoint]: Could not create Raya application: ERROR in get_arguments() method: Argument '('-m', '--mandatory-arg')' is not valid or not definedProviding the mandatory argument:
python3 get_args/ --auto-run -m Example
Example log output:
[INFO] [timestamp] [pyraya.get_args]: Auto running the app [INFO] [timestamp] [pyraya.get_args]: Hello from setup() [WARNING] [timestamp] [pyraya.get_args]: Mandatory argument: Example [WARNING] [timestamp] [pyraya.get_args]: Default argument: default_value [INFO] [timestamp] [pyraya.get_args]: Hello from loop() 1 ... [INFO] [timestamp] [pyraya.get_args]: Hello from finish()
Providing both the mandatory and optional arguments:
python3 get_args/ --auto-run -m Mandatory -d Default
Example log output:
[INFO] [timestamp] [pyraya.get_args]: Auto running the app [INFO] [timestamp] [pyraya.get_args]: Hello from setup() [WARNING] [timestamp] [pyraya.get_args]: Mandatory argument: Mandatory [WARNING] [timestamp] [pyraya.get_args]: Default argument: Default [INFO] [timestamp] [pyraya.get_args]: Hello from loop() 1 ... [INFO] [timestamp] [pyraya.get_args]: Hello from finish()
Behavior¶
The application initializes and logs the values of the provided arguments.
A loop runs five iterations, logging messages in each cycle.
After five iterations, the application exits.
Key Notes¶
The -m argument is mandatory; the application will not start without it.
The -d argument is optional; if not provided, it defaults to “default_value”.
The application runs a simple loop and then terminates.