Parsing from Terminal Arguments

  • Terminal parameters in the list of dictionaries

    The keys to be set for using the terminal arguments are:

  • terminal_help (Required)

    • The help string for explaining the variable.
  • terminal_name (Required)
    • The name of the variable to be scanned after the two minus, like: --example-str
  • terminal_name_short

    • The short name of the variable to be scannd after a single minus, like: -es
  • Boolean variable

    When parsing a boolean variable, keep in mind that if you set it over as a terminal argument, when parsed, it will always be set at TRUE

  • Using the Environmental Variables

    Here is how you can add your configuration file to the package:

from fejao_config_parser import my_config

config = [
    {
        "name": "example_string",
        "type": "string",
        "default": "default_string_value",
        "terminal_help": "Example of a string terminal variable.",
        "terminal_name": "example-str",
        "terminal_name_short": "es",
    },
    {
        "name": "example_bool",
        "type": "bool",
        "default": False,
        "terminal_help": "Example of a boolean terminal variable.",
        "terminal_name": "example-bool",
        "terminal_name_short": "eb",
    },
    {
        "name": "example_int",
        "type": "int",
        "default": 42,
        "terminal_help": "Example of a integer terminal variable.",
        "terminal_name": "example-int",
        "terminal_name_short": "ei",
    },
    {
        "name": "example_float",
        "type": "float",
        "default": 4.2,
        "terminal_help": "Example of a float terminal variable.",
        "terminal_name": "example-float",
        "terminal_name_short": "ef",
    },
    {
        "name": "example_list",
        "type": "list",
        "default": [1, 2, 3],
        "terminal_help": "Example of a float list variable.",
        "terminal_name": "example-list",
        "terminal_name_short": "el",
    },
    {
        "name": "example_dict",
        "type": "dict",
        "default": {
            "key_1": "dict_deafult_1",
            "key_2": "dict_deafult_2",
        },
        "terminal_help": "Example of a float dictionary variable.",
        "terminal_name": "example-dict",
        "terminal_name_short": "ed",
    },
]

config = my_config(
    config=config,
    description="This is an example for using terminal arguments from the fejao_config_parser package"
)

Here is an example of starting your project from the terminal using the environmental variables:

python your_project_file.py \
--example-str from_terminal_value \
--example-bool \
--ei 24 \
--example-float 2.4 \
--example-list [4, 5, 6] \
--example-dict '{"key_1": "env_val_1", "key_2": "env_val_2"}'

As you can see, the example-bool don't need to parse a value, because when parsed, it will always be TRUE

For the example-int we used the terminal_name_short for setting the value

You can access the values as:

print(f"example_string: {config.example_string}")
print(f"example_bool: {config.example_bool}")
print(f"example_int: {config.example_int}")
print(f"example_float: {config.example_float}")
print(f"example_list: {config.example_list}")
print(f"example_dict: {config.example_dict}")

The ouput will be:

example_string: "from_terminal_value"
example_bool: True
example_int: 24
example_float: 2.4
example_list: [4, 5, 6]
example_dict: {"key_1": "env_val_1", "key_2": "env_val_2"}