39 lines
904 B
Python
39 lines
904 B
Python
import sys
|
|
import logging
|
|
|
|
|
|
def get_string_arg(args, required):
|
|
"""
|
|
Take an array of element, take first element and return it stripped.
|
|
If array is empty or None, print an error message with required and exit
|
|
in error.
|
|
|
|
:param args: an array of arguments. Can be empty or None
|
|
:param required: the message to print in no args (or None)
|
|
:return: The arg stripped
|
|
"""
|
|
if not args:
|
|
print(f"Missing {required}")
|
|
sys.exit(1)
|
|
|
|
logging.debug(args)
|
|
return args[0].strip()
|
|
|
|
|
|
# TODO Move this function
|
|
def arg_string(arg, required=""):
|
|
# TODO To meld with get_string_args
|
|
if required and arg.startswith("-"):
|
|
print("required ", required)
|
|
sys.exit("1")
|
|
else:
|
|
return arg.strip()
|
|
|
|
|
|
def arg_number(arg): # , required=""):
|
|
if not arg.isdigit():
|
|
print("Invalid value")
|
|
sys.exit(1)
|
|
|
|
return int(arg)
|