argtools - Argparser fun

Parser types for command-line options, arguments and sub-commands

torxtools.argtools.is_dir(value: str) Callable

Returns path if path is an existing regular directory. This follows symbolic links

Parameters:

value (str) – value passed from argparser

Returns:

value passed from argparser

Return type:

str

Example

parser.add_argument(
    "-f", "--dir"
    type=torxtools.argtools.is_dir
)
torxtools.argtools.is_file(value: str) Callable

Returns path if path is an existing regular file. This follows symbolic links

Parameters:

value (str) – value passed from argparser

Returns:

value passed from argparser

Return type:

str

Example

parser.add_argument(
    "-f", "--file"
    type=torxtools.argtools.is_file
)
torxtools.argtools.is_int_negative(value: int) int

Verify that argument passed is a negative integer.

Parameters:

value (int) – value passed from argparser

Returns:

value passed from argparser

Return type:

int

Example

parser.add_argument(
    "--temperature", "-t",
    dest="temperature",
    help="[C] Temperature colder than freezing point",
    type=torxtools.argtools.is_int_negative,
    default=-50,
)
torxtools.argtools.is_int_negative_or_zero(value: int) int

Verify that argument passed is a negative integer or zero.

Parameters:

value (int) – value passed from argparser

Returns:

value passed from argparser

Return type:

int

Example

parser.add_argument(
    "--temperature", "-t",
    dest="temperature",
    help="[C] Temperature colder than freezing point",
    type=torxtools.argtools.is_int_negative_or_zero,
    default=-50,
)
torxtools.argtools.is_int_positive(value: int) int

Verify that argument passed is a positive integer.

Parameters:

value (int) – value passed from argparser

Returns:

value passed from argparser

Return type:

int

Example

parser.add_argument(
    "--size", "-s",
    dest="size",
    help="[MB] Minimal size of attachment",
    type=torxtools.argtools.is_int_positive,
    default=100,
)
torxtools.argtools.is_int_positive_or_zero(value: int) int

Verify that argument passed is a positive integer or zero.

Parameters:

value (int) – value passed from argparser

Returns:

value passed from argparser

Return type:

int

Example

parser.add_argument(
    "--size", "-s",
    dest="size",
    help="[MB] Minimal size of attachment",
    type=torxtools.argtools.is_int_positive_or_zero,
    default=100,
)