From fff5c8bc98b51c093ccd332d41a90c2e5bfbd82f Mon Sep 17 00:00:00 2001 From: Ivan Habunek Date: Sat, 26 Aug 2017 11:33:36 +0200 Subject: [PATCH] Allow passing instance and email to login command --- CHANGELOG.md | 4 ++++ toot/commands.py | 28 +++++++++++++++------------- toot/console.py | 11 ++++++++++- 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cc6dea2..815e680 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ Changelog --------- +**0.13.0 (TBA)** + +* Allow passing `--instance` and `--email` to login command + **0.12.0 (2016-05-08)** * Add option to disable ANSI color in output (#15) diff --git a/toot/commands.py b/toot/commands.py index bb3edf2..9f953eb 100644 --- a/toot/commands.py +++ b/toot/commands.py @@ -35,25 +35,27 @@ def register_app(instance): return app -def create_app_interactive(): - print_out("Choose an instance [{}]: ".format(DEFAULT_INSTANCE), end="") - - instance = input() +def create_app_interactive(instance=None): if not instance: - instance = DEFAULT_INSTANCE + print_out("Choose an instance [{}]: ".format(DEFAULT_INSTANCE), end="") + instance = input() + if not instance: + instance = DEFAULT_INSTANCE return config.load_app(instance) or register_app(instance) -def login_interactive(app): - print_out("\nLog in to {}".format(app.instance)) +def login_interactive(app, email=None): + print_out("Log in to {}".format(app.instance)) + + if email: + print_out("Email: {}".format(email)) + + while not email: + email = input('Email: ') - email = input('Email: ') password = getpass('Password: ') - if not email or not password: - raise ConsoleError("Email and password cannot be empty.") - try: print_out("Authenticating...") response = api.login(app, email, password) @@ -199,8 +201,8 @@ def auth(app, user, args): def login(app, user, args): - app = create_app_interactive() - login_interactive(app) + app = create_app_interactive(instance=args.instance) + login_interactive(app, args.email) print_out() print_out("✓ Successfully logged in.") diff --git a/toot/console.py b/toot/console.py index 3b22750..6034ca7 100644 --- a/toot/console.py +++ b/toot/console.py @@ -43,7 +43,16 @@ AUTH_COMMANDS = [ Command( name="login", description="Log into a Mastodon instance", - arguments=[], + arguments=[ + (["-i", "--instance"], { + "type": str, + "help": 'mastodon instance to log into e.g. "mastodon.social"', + }), + (["-e", "--email"], { + "type": str, + "help": 'email address to log in with', + }), + ], require_auth=False, ), Command(