forked from cmccabe/linkulator2
Ask for confirmation before creating a new category
This commit is contained in:
parent
67943dde14
commit
fde45a2417
|
@ -273,6 +273,14 @@ def is_valid_input(entry: str) -> bool:
|
|||
return False
|
||||
return True
|
||||
|
||||
def is_correct_category(entry: str) -> bool:
|
||||
"""Make sure the user purposefully created a new category and not by
|
||||
accident (mistyped, tried to use category number instead of name)"""
|
||||
if entry not in [ record["name"] for record in categories ]:
|
||||
question = "Do you want to create a new category '{}'? Y/[N]".format(entry)
|
||||
answer = input(question).lower().strip()
|
||||
return answer != "" and answer[0] == "y"
|
||||
return True
|
||||
|
||||
def get_input(item: str) -> str:
|
||||
"""Get user input with the specified prompt, validate and return it, or
|
||||
|
@ -312,6 +320,8 @@ def post_link() -> int:
|
|||
try:
|
||||
url = get_input("URL")
|
||||
category = get_input("Category")
|
||||
while not is_correct_category(category):
|
||||
category = get_input("Category")
|
||||
title = get_input("Title")
|
||||
except ValueError:
|
||||
print("Post cancelled")
|
||||
|
|
Loading…
Reference in New Issue