Added default values for taking input

This commit is contained in:
strNophix 2022-04-08 14:20:40 +02:00
parent cd736a2606
commit acda51a6b4

@ -18,9 +18,11 @@ RE_TEXT = re.compile(r"^\w+$")
RE_NUM = re.compile(r"^\d+$")
def _take_input(prompt: str, pattern: re.Pattern) -> str:
def _take_input(prompt: str, pattern: re.Pattern, default: str="") -> str:
while True:
i = input(prompt)
if i == "":
i = default
if pattern.match(i):
return i
@ -36,22 +38,22 @@ def main() -> int:
break
if c == "1":
customer_name = _take_input("Customer name (example=opc): ",
customer_name = _take_input("Customer name (example=opg): ",
RE_TEXT)
env_name = _take_input("Environment name (example=prod): ",
RE_TEXT)
amnt_nginx_web = _take_input(
"Number of nginx webservers (example=1): ", RE_NUM)
"Number of nginx webservers (default=1): ", RE_NUM, default="1")
amnt_nginx_lb = _take_input(
"Number of nginx loadbalancers (example=1): ", RE_NUM)
"Number of nginx loadbalancers (default=1): ", RE_NUM, default="1")
amnt_psql = _take_input(
"Number of postgres instances (example=1): ", RE_NUM)
"Number of postgres instances (default=1): ", RE_NUM, default="1")
ip_format = _take_input(
"Format of ip (example=192.168.56.{}, `{}` will be replaced with the correct octet at runtime): ",
re.compile(r".+"))
"Format of ip (default=192.168.56.{}, `{}` will be replaced with the correct octet at runtime): ",
re.compile(r".+"), default="192.168.56.{}")
ip_int = _take_input(
"Number to start formatting the IP from (example=10): ",
RE_NUM)
"Number to start formatting the IP from (default=10): ",
RE_NUM, default="10")
sub.call([
"python3", "cli.py", "create", customer_name, env_name,
@ -61,21 +63,21 @@ def main() -> int:
])
if c == "2":
customer_name = _take_input("Customer name (example=opc): ",
customer_name = _take_input("Customer name (example=opg): ",
RE_TEXT)
env_name = _take_input("Environment name (example=prod): ",
RE_TEXT)
sub.call(["python3", "cli.py", "delete", customer_name, env_name])
if c == "3":
customer_name = _take_input("Customer name (example=opc): ",
customer_name = _take_input("Customer name (example=opg): ",
RE_TEXT)
env_name = _take_input("Environment name (example=prod): ",
RE_TEXT)
sub.call(["python3", "cli.py", "recover", customer_name, env_name])
if c == "4":
customer_name = _take_input("Customer name (example=opc): ",
customer_name = _take_input("Customer name (example=opg): ",
RE_TEXT)
sub.call(["python3", "cli.py", "list", customer_name])