1
0
mirror of https://github.com/ihabunek/toot.git synced 2025-02-02 15:07:51 -05:00

Allow passing instance and email to login command

This commit is contained in:
Ivan Habunek 2017-08-26 11:33:36 +02:00
parent 65da61b8b6
commit fff5c8bc98
3 changed files with 29 additions and 14 deletions

View File

@ -1,6 +1,10 @@
Changelog Changelog
--------- ---------
**0.13.0 (TBA)**
* Allow passing `--instance` and `--email` to login command
**0.12.0 (2016-05-08)** **0.12.0 (2016-05-08)**
* Add option to disable ANSI color in output (#15) * Add option to disable ANSI color in output (#15)

View File

@ -35,25 +35,27 @@ def register_app(instance):
return app return app
def create_app_interactive(): def create_app_interactive(instance=None):
print_out("Choose an instance [<green>{}</green>]: ".format(DEFAULT_INSTANCE), end="")
instance = input()
if not instance: 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) return config.load_app(instance) or register_app(instance)
def login_interactive(app): def login_interactive(app, email=None):
print_out("\nLog in to <green>{}</green>".format(app.instance)) print_out("Log in to <green>{}</green>".format(app.instance))
if email:
print_out("Email: <green>{}</green>".format(email))
while not email:
email = input('Email: ')
email = input('Email: ')
password = getpass('Password: ') password = getpass('Password: ')
if not email or not password:
raise ConsoleError("Email and password cannot be empty.")
try: try:
print_out("Authenticating...") print_out("Authenticating...")
response = api.login(app, email, password) response = api.login(app, email, password)
@ -199,8 +201,8 @@ def auth(app, user, args):
def login(app, user, args): def login(app, user, args):
app = create_app_interactive() app = create_app_interactive(instance=args.instance)
login_interactive(app) login_interactive(app, args.email)
print_out() print_out()
print_out("<green>✓ Successfully logged in.</green>") print_out("<green>✓ Successfully logged in.</green>")

View File

@ -43,7 +43,16 @@ AUTH_COMMANDS = [
Command( Command(
name="login", name="login",
description="Log into a Mastodon instance", 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, require_auth=False,
), ),
Command( Command(