Allow passing instance and email to login command - toot - Unnamed repository; edit this file 'description' to name the repository.
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) LICENSE
---
(DIR) commit fff5c8bc98b51c093ccd332d41a90c2e5bfbd82f
(DIR) parent 65da61b8b6808dd94b6e30e026452d2d9878a3f7
(HTM) Author: Ivan Habunek <ivan@habunek.com>
Date: Sat, 26 Aug 2017 11:33:36 +0200
Allow passing instance and email to login command
Diffstat:
CHANGELOG.md | 4 ++++
toot/commands.py | 28 +++++++++++++++-------------
toot/console.py | 11 ++++++++++-
3 files changed, 29 insertions(+), 14 deletions(-)
---
(DIR) diff --git 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)
(DIR) diff --git a/toot/commands.py b/toot/commands.py
@@ -35,24 +35,26 @@ def register_app(instance):
return app
-def create_app_interactive():
- print_out("Choose an instance [<green>{}</green>]: ".format(DEFAULT_INSTANCE), end="")
-
- instance = input()
+def create_app_interactive(instance=None):
if not instance:
- instance = DEFAULT_INSTANCE
+ print_out("Choose an instance [<green>{}</green>]: ".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 <green>{}</green>".format(app.instance))
+def login_interactive(app, email=None):
+ print_out("Log in to <green>{}</green>".format(app.instance))
- email = input('Email: ')
- password = getpass('Password: ')
+ if email:
+ print_out("Email: <green>{}</green>".format(email))
- if not email or not password:
- raise ConsoleError("Email and password cannot be empty.")
+ while not email:
+ email = input('Email: ')
+
+ password = getpass('Password: ')
try:
print_out("Authenticating...")
@@ -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("<green>✓ Successfully logged in.</green>")
(DIR) diff --git 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(