62 lines
2.3 KiB
Python
62 lines
2.3 KiB
Python
from getpass import getpass
|
|
from urllib.parse import urlparse
|
|
|
|
from . import storage
|
|
from .utils import display_help, stack_formatter, status_formatter, restart_formatter
|
|
from .parser import Credentials, credentialparser
|
|
from .communicate import DockgeConnection
|
|
|
|
def exec_command(command, extra_args):
|
|
match command:
|
|
case "help":
|
|
display_help(extra_args)
|
|
case "login":
|
|
if len(extra_args) > 0:
|
|
credentials = credentialparser.parse_args(extra_args, namespace=Credentials)
|
|
storage.put("username", credentials.username, encoded=True)
|
|
storage.put("password", credentials.password, encoded=True)
|
|
return
|
|
storage.put("username", input("Username: "), encoded=True)
|
|
storage.put("password", getpass("Password: "), encoded=True)
|
|
case "logout":
|
|
storage.remove("username")
|
|
storage.remove("password")
|
|
case "host":
|
|
if len(extra_args) > 0:
|
|
res = urlparse(extra_args[0])
|
|
if all([res.scheme, res.netloc]):
|
|
host = extra_args[0].rstrip("/").replace("wss://", "").replace("https://", "")
|
|
storage.put("host", host)
|
|
else:
|
|
raise ValueError(f"Malformed URL {extra_args[0]}")
|
|
print(storage.get("host"))
|
|
case "exit":
|
|
storage.clear()
|
|
case "list":
|
|
con = DockgeConnection()
|
|
con.connect_and_login()
|
|
stack_formatter(con.list_stacks())
|
|
con.disconnect()
|
|
case "status":
|
|
if extra_args is None:
|
|
raise ValueError
|
|
con = DockgeConnection()
|
|
con.connect_and_login()
|
|
status_formatter(con.list_stack(extra_args[0]))
|
|
con.disconnect()
|
|
case "restart":
|
|
if extra_args is None:
|
|
raise ValueError
|
|
con = DockgeConnection()
|
|
con.connect_and_login()
|
|
restart_formatter(con.restart(extra_args[0]))
|
|
con.disconnect()
|
|
case "debug":
|
|
con = DockgeConnection()
|
|
con.connect_and_login()
|
|
stack_formatter(con.list_stacks())
|
|
print("fgo-ta-com", con.list_stack("fgo-ta-com"))
|
|
con.disconnect()
|
|
case _:
|
|
print("Not implemented")
|