From df9d419919bbd16fd0bfdde8962709a1edd70f6a Mon Sep 17 00:00:00 2001 From: magical Date: Sat, 6 Aug 2022 05:09:57 +0000 Subject: [PATCH] move some global code into main --- clients/urwid/main.py | 49 +++++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/clients/urwid/main.py b/clients/urwid/main.py index d95b505..0126f36 100644 --- a/clients/urwid/main.py +++ b/clients/urwid/main.py @@ -37,19 +37,8 @@ import json import os import re -# XxX_N0_4rgP4rs3_XxX ###yoloswag -def get_arg(key, default=None, get_value=True): - try: - spec = argv.index("--" + key) - value = argv[spec + 1] if get_value else True - except ValueError: # --key not specified - value = default - except IndexError: # flag given but no value - exit("invalid format for --" + key) - return value - -if get_arg("help", False, False): - print("""BBJ Urwid Client +help_text = """\ +BBJ Urwid Client Available options: --help: this message --https: enable use of https, requires host support @@ -62,16 +51,7 @@ Available environment variables: BBJ_PASSWORD: set your password to log in automatically. if the password is wrong, will prompt you as normal. Please note that these environment variables need to be exported, and are -visible to all other programs run from your shell.""") - exit() - -try: - network = BBJ(get_arg("host", "127.0.0.1"), - get_arg("port", 7099), - get_arg("https", False, False)) -except URLError as e: - # print the connection error in red - exit("\033[0;31m%s\033[0m" % repr(e)) +visible to all other programs run from your shell.""" obnoxious_logo = """ % _ * ! * @@ -2572,8 +2552,31 @@ def wipe_screen(*_): call("clear", shell=True) app.loop.start() +# XxX_N0_4rgP4rs3_XxX ###yoloswag +def get_arg(key, default=None, get_value=True): + try: + spec = argv.index("--" + key) + value = argv[spec + 1] if get_value else True + except ValueError: # --key not specified + value = default + except IndexError: # flag given but no value + exit("invalid format for --" + key) + return value def main(): + if get_arg("help", False, False): + print(help_text) + exit() + + global network + try: + network = BBJ(get_arg("host", "127.0.0.1"), + get_arg("port", 7099), + get_arg("https", False, False)) + except URLError as e: + # print the connection error in red + exit("\033[0;31m%s\033[0m" % repr(e)) + global app app = App() call("clear", shell=True)