Remove -p option, ensure appropriate menu flow from post_link
This commit is contained in:
parent
c804bbd68e
commit
8cb4201c20
13
linkulator
13
linkulator
|
@ -88,7 +88,6 @@ def print_categories():
|
|||
graceful_exit()
|
||||
elif view_cat == "p":
|
||||
posts.post_link()
|
||||
return
|
||||
else:
|
||||
try:
|
||||
view_cat = categories[int(view_cat) - 1]
|
||||
|
@ -297,18 +296,6 @@ def parse_command():
|
|||
print_categories()
|
||||
elif args[0] in ["-h", "--help", "help"]:
|
||||
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:
|
||||
print("Unknown command: {}".format(args[0]))
|
||||
|
||||
|
|
23
posts.py
23
posts.py
|
@ -3,7 +3,6 @@
|
|||
import getpass
|
||||
import os
|
||||
import readline
|
||||
import sys
|
||||
import time
|
||||
|
||||
import config
|
||||
|
@ -44,18 +43,17 @@ def is_valid(entry: str) -> bool:
|
|||
|
||||
|
||||
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:
|
||||
i: str = rlinput(item + ": ", prefill)
|
||||
if i == "":
|
||||
sys.exit(0)
|
||||
raise ValueError("Empty values are not permitted")
|
||||
if is_valid(i):
|
||||
return i
|
||||
|
||||
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"""
|
||||
if os.path.exists(config.USER.datafile):
|
||||
append_write = "a" # append if already exists
|
||||
|
@ -75,15 +73,18 @@ def save_link(link) -> None:
|
|||
print("Link added!")
|
||||
|
||||
|
||||
def post_link(prefill: str = "") -> None:
|
||||
"""High-level """
|
||||
def post_link(prefill: str = ""):
|
||||
"""Handles the link posting process"""
|
||||
print("Enter link information here. Leaving any field blank aborts post.")
|
||||
|
||||
link = Link()
|
||||
|
||||
link.url = get_input("URL", prefill)
|
||||
link.category = get_input("Category", "")
|
||||
link.title = get_input("Title", "")
|
||||
try:
|
||||
link.url = get_input("URL", prefill)
|
||||
link.category = get_input("Category", "")
|
||||
link.title = get_input("Title", "")
|
||||
except ValueError:
|
||||
print("Post not recorded")
|
||||
return
|
||||
link.timestamp = str(time.time())
|
||||
|
||||
save_link(link)
|
||||
|
|
Loading…
Reference in New Issue