#!/bin/env python import typer, json, os, sys from pathlib import Path from .config import Config from getpass import getpass from prettytable import PrettyTable import requests from typing import Annotated VERSION = "1.0" app = typer.Typer() config = Config() config.load() API_URI = config.get("API_URI") @app.command() def version(): print(f"Version: {VERSION}") @app.command() def login(): username: str = input("Username: ") password: str = getpass("Password: ") result = requests.post(API_URI+"/api/login/", json={"username":username, "password":password}) data = result.json() table = PrettyTable() table.field_names = ["Status Code", "Message"] if result.status_code != 200: table.add_row([result.status_code, data["detail"]]) else: table.add_row([result.status_code, "success"]) config.set("token", data["access_token"]) config.save() print(table) @app.command() def api_uri(url: Annotated[str, typer.Argument(help="The API Url (without /api...)")]): config.set("API_URI", url) if __name__ == "__main__": app()