Remove -p option, ensure appropriate menu flow from post_link

This commit is contained in:
asdf 2019-12-07 12:42:41 +11:00
parent c804bbd68e
commit 8cb4201c20
2 changed files with 12 additions and 24 deletions

View File

@ -88,7 +88,6 @@ def print_categories():
graceful_exit() graceful_exit()
elif view_cat == "p": elif view_cat == "p":
posts.post_link() posts.post_link()
return
else: else:
try: try:
view_cat = categories[int(view_cat) - 1] view_cat = categories[int(view_cat) - 1]
@ -297,18 +296,6 @@ def parse_command():
print_categories() print_categories()
elif args[0] in ["-h", "--help", "help"]: elif args[0] in ["-h", "--help", "help"]:
print(help_text) print(help_text)
elif args[0] in ["-p", "--post", "-p"] and len(sys.argv) > 2:
print_banner()
posts.post_link(args[1])
parse_ignore_file()
build_menu()
print_categories()
elif args[0] in ["-p", "--post", "-p"]:
print_banner()
posts.post_link()
parse_ignore_file()
build_menu()
print_categories()
else: else:
print("Unknown command: {}".format(args[0])) print("Unknown command: {}".format(args[0]))

View File

@ -3,7 +3,6 @@
import getpass import getpass
import os import os
import readline import readline
import sys
import time import time
import config import config
@ -44,18 +43,17 @@ def is_valid(entry: str) -> bool:
def get_input(item: str, prefill) -> str: def get_input(item: str, prefill) -> str:
"""Get user input with the specified prompt, validate and return it or exit""" """Get user input with the specified prompt, validate and return it, or break if invalid"""
while True: while True:
i: str = rlinput(item + ": ", prefill) i: str = rlinput(item + ": ", prefill)
if i == "": if i == "":
sys.exit(0) raise ValueError("Empty values are not permitted")
if is_valid(i): if is_valid(i):
return i return i
print('Pipes, "|", are illegal characters in Linkulator. Please try again.') print('Pipes, "|", are illegal characters in Linkulator. Please try again.')
def save_link(link) -> None: def save_link(link):
"""Saves the specified link data to the user's data file""" """Saves the specified link data to the user's data file"""
if os.path.exists(config.USER.datafile): if os.path.exists(config.USER.datafile):
append_write = "a" # append if already exists append_write = "a" # append if already exists
@ -75,15 +73,18 @@ def save_link(link) -> None:
print("Link added!") print("Link added!")
def post_link(prefill: str = "") -> None: def post_link(prefill: str = ""):
"""High-level """ """Handles the link posting process"""
print("Enter link information here. Leaving any field blank aborts post.") print("Enter link information here. Leaving any field blank aborts post.")
link = Link() link = Link()
try:
link.url = get_input("URL", prefill) link.url = get_input("URL", prefill)
link.category = get_input("Category", "") link.category = get_input("Category", "")
link.title = get_input("Title", "") link.title = get_input("Title", "")
except ValueError:
print("Post not recorded")
return
link.timestamp = str(time.time()) link.timestamp = str(time.time())
save_link(link) save_link(link)