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 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)