move some global code into main

master
magical 2022-08-06 05:09:57 +00:00
parent 6e30125fb8
commit df9d419919
1 changed files with 26 additions and 23 deletions

View File

@ -37,19 +37,8 @@ import json
import os import os
import re import re
# XxX_N0_4rgP4rs3_XxX ###yoloswag help_text = """\
def get_arg(key, default=None, get_value=True): BBJ Urwid Client
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
Available options: Available options:
--help: this message --help: this message
--https: enable use of https, requires host support --https: enable use of https, requires host support
@ -62,16 +51,7 @@ Available environment variables:
BBJ_PASSWORD: set your password to log in automatically. BBJ_PASSWORD: set your password to log in automatically.
if the password is wrong, will prompt you as normal. if the password is wrong, will prompt you as normal.
Please note that these environment variables need to be exported, and are Please note that these environment variables need to be exported, and are
visible to all other programs run from your shell.""") 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))
obnoxious_logo = """ obnoxious_logo = """
% _ * ! * % _ * ! *
@ -2572,8 +2552,31 @@ def wipe_screen(*_):
call("clear", shell=True) call("clear", shell=True)
app.loop.start() 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(): 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 global app
app = App() app = App()
call("clear", shell=True) call("clear", shell=True)