pivotalcli/commands/login.py

21 lines
537 B
Python

import click
import api.me
from config import Config
from .cli import cli
@cli.command("login")
@click.option("--email", prompt=True)
@click.option("--password", prompt=True, hide_input=True)
def login(email: str, password: str) -> None:
user = api.me.get(email, password)
print()
print(f"Logged in successfully as {user['name']} (@{user['username']}).")
Config["user"]["api_token"] = user["api_token"]
Config["user"]["initials"] = user["initials"]
Config["user"]["email"] = user["email"]
Config.write()