32 lines
952 B
Python
32 lines
952 B
Python
|
from getpass import getpass
|
||
|
from urllib.parse import urlparse
|
||
|
from . import storage
|
||
|
|
||
|
|
||
|
def exec_command(command, extra_args):
|
||
|
match command:
|
||
|
case "login":
|
||
|
storage.set("username", input("Username: "), encoded=True)
|
||
|
storage.set("password", getpass("Password: "), encoded=True)
|
||
|
return
|
||
|
case "logout":
|
||
|
storage.remove("username")
|
||
|
storage.remove("password")
|
||
|
return
|
||
|
case "host":
|
||
|
if len(extra_args) > 0:
|
||
|
res = urlparse(extra_args[0])
|
||
|
if all([res.scheme, res.netloc]):
|
||
|
storage.set("host", extra_args[0])
|
||
|
else:
|
||
|
raise Exception(f"Malformed URL {extra_args[0]}")
|
||
|
return
|
||
|
print(storage.get("host"))
|
||
|
case "exit":
|
||
|
storage.clear()
|
||
|
return
|
||
|
case _:
|
||
|
print("Not implemented")
|
||
|
return
|
||
|
|