pivotalcli/commands/login.py

20 lines
493 B
Python
Raw Normal View History

2018-07-21 12:36:02 +00:00
import click
2018-04-03 10:56:07 +00:00
import api.me
from config import Config
2018-07-21 12:36:02 +00:00
from .cli import cli
2018-04-03 10:56:07 +00:00
2018-07-21 12:36:02 +00:00
@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)
2018-04-03 10:56:07 +00:00
2018-07-21 12:36:02 +00:00
print()
print(f"Logged in successfully as {user['name']} (@{user['username']}).")
2018-04-03 10:56:07 +00:00
2018-07-21 12:36:02 +00:00
Config['user']['api_token'] = user['api_token']
Config['user']['initials'] = user['initials']
2018-04-03 10:56:07 +00:00
Config.write()