validators
env_var(arg_value)
¶
env_var_or_empty(arg_value)
¶
Read a value from the environment.
Unlike the env_var validator, this will only
allow the arg_value
to pass through if is not in the form of an
environment variable. That is, if the value is all uppercase letters and
underscores it will attempt to read from the environment and return an empty
string if not defined.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
arg_value |
str
|
The input provided by argparse. |
required |
Returns:
Type | Description |
---|---|
str
|
The environment variable value if it exists. Otherwise, empty string. |
Source code in m/cli/validators.py
validate_file_exists(path)
¶
Assert that a file exists.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
str
|
The path to the file. |
required |
Raises:
Type | Description |
---|---|
ArgumentTypeError
|
If the file does not exist. |
Returns:
Type | Description |
---|---|
str
|
The path if it exists. |
Source code in m/cli/validators.py
validate_json_payload(file_path)
¶
Return a dictionary from the contents of file_path.
This is a string that tell us to read from a file, stdin or just plain json data.
It can be used parse yaml
files as well. The extension should be
.yaml
or .yml
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_path |
str
|
A string with the json payload. If it starts with |
required |
Raises:
Type | Description |
---|---|
ArgumentTypeError
|
If the file_path is meant to be a valid path and it does not exist. |
Returns:
Type | Description |
---|---|
Any
|
A parsed json payload |
Source code in m/cli/validators.py
validate_non_empty_str(arg_value)
¶
Return the value as long as its not empty.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
arg_value |
str
|
The input provided by argparse. |
required |
Raises:
Type | Description |
---|---|
ArgumentTypeError
|
If the input is not provided. |
Returns:
Type | Description |
---|---|
str
|
The value if non empty. |
Source code in m/cli/validators.py
validate_payload(file_path)
¶
Return the raw payload.
This allows us to read from a file or the stdin stream.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_path |
str
|
A string with the payload. If it starts with |
required |
Raises:
Type | Description |
---|---|
ArgumentTypeError
|
If the file_path is meant to be a valid path and it does not exist. |
Returns:
Type | Description |
---|---|
str
|
The payload found in the file. |