Merge pull request 'Ask for confirmation before creating a new category' (#100) from isti/linkulator2:master into master
Reviewed-on: #100
This commit is contained in:
commit
65c9a070ad
|
@ -273,6 +273,14 @@ def is_valid_input(entry: str) -> bool:
|
||||||
return False
|
return False
|
||||||
return True
|
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:
|
def get_input(item: str) -> str:
|
||||||
"""Get user input with the specified prompt, validate and return it, or
|
"""Get user input with the specified prompt, validate and return it, or
|
||||||
|
@ -312,6 +320,8 @@ def post_link() -> int:
|
||||||
try:
|
try:
|
||||||
url = get_input("URL")
|
url = get_input("URL")
|
||||||
category = get_input("Category")
|
category = get_input("Category")
|
||||||
|
while not is_correct_category(category):
|
||||||
|
category = get_input("Category")
|
||||||
title = get_input("Title")
|
title = get_input("Title")
|
||||||
except ValueError:
|
except ValueError:
|
||||||
print("Post cancelled")
|
print("Post cancelled")
|
||||||
|
|
Loading…
Reference in New Issue