From 01afbe1f2f7682a16ee0346339eb2ed4219fc667 Mon Sep 17 00:00:00 2001 From: Daniel Schwarz Date: Sat, 27 May 2023 16:25:13 -0400 Subject: [PATCH 1/2] If toot activate is invoked without an account, show list of accounts --- toot/commands.py | 8 +++++++- toot/config.py | 5 +++++ toot/console.py | 6 +++++- toot/output.py | 5 +++++ 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/toot/commands.py b/toot/commands.py index 0a76590..d4bd625 100644 --- a/toot/commands.py +++ b/toot/commands.py @@ -9,7 +9,7 @@ from toot.auth import login_interactive, login_browser_interactive, create_app_i from toot.exceptions import ApiError, ConsoleError from toot.output import (print_lists, print_out, print_instance, print_account, print_acct_list, print_search_results, print_timeline, print_notifications, print_tag_list, - print_list_accounts) + print_list_accounts, print_user_list) from toot.tui.utils import parse_datetime from toot.utils import args_get_instance, delete_tmp_status_file, editor_input, multiline_input, EOF_KEY @@ -335,6 +335,12 @@ def logout(app, user, args): def activate(app, user, args): + if not args.account: + print_out("Specify one of the following user accounts to activate:\n") + print_user_list(config.get_user_list()) + print_out("\n") + return + user = config.load_user(args.account, throw=True) config.activate_user(user) print_out("✓ User {} active".format(config.user_id(user))) diff --git a/toot/config.py b/toot/config.py index 6404467..cff9856 100644 --- a/toot/config.py +++ b/toot/config.py @@ -120,6 +120,11 @@ def load_user(user_id, throw=False): raise ConsoleError("User '{}' not found".format(user_id)) +def get_user_list(): + config = load_config() + return config['users'] + + def modify_config(f): @wraps(f) def wrapper(*args, **kwargs): diff --git a/toot/console.py b/toot/console.py index 14433aa..da4f3ce 100644 --- a/toot/console.py +++ b/toot/console.py @@ -190,6 +190,10 @@ common_auth_args = [ account_arg = (["account"], { "help": "account name, e.g. 'Gargron@mastodon.social'", }) +optional_account_arg = (["account"], { + "nargs": "?", + "help": "account name, e.g. 'Gargron@mastodon.social'", +}) instance_arg = (["-i", "--instance"], { "type": str, @@ -293,7 +297,7 @@ AUTH_COMMANDS = [ Command( name="activate", description="Switch between logged in accounts.", - arguments=[account_arg], + arguments=[optional_account_arg], require_auth=False, ), Command( diff --git a/toot/output.py b/toot/output.py index c89aca9..f722fae 100644 --- a/toot/output.py +++ b/toot/output.py @@ -203,6 +203,11 @@ def print_acct_list(accounts): print_out(f"* @{account['acct']} {account['display_name']}") +def print_user_list(users): + for user in users: + print_out(f"{user}") + + def print_tag_list(tags): if tags: for tag in tags: From 7b08e39f00bc1fc017728351044e5aee58aa59da Mon Sep 17 00:00:00 2001 From: Ivan Habunek Date: Thu, 22 Jun 2023 11:33:07 +0200 Subject: [PATCH 2/2] Decrease the amount of color --- toot/commands.py | 3 +-- toot/output.py | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/toot/commands.py b/toot/commands.py index d4bd625..dbb5eb6 100644 --- a/toot/commands.py +++ b/toot/commands.py @@ -336,9 +336,8 @@ def logout(app, user, args): def activate(app, user, args): if not args.account: - print_out("Specify one of the following user accounts to activate:\n") + print_out("Specify one of the following user accounts to activate:\n") print_user_list(config.get_user_list()) - print_out("\n") return user = config.load_user(args.account, throw=True) diff --git a/toot/output.py b/toot/output.py index f722fae..3414cdb 100644 --- a/toot/output.py +++ b/toot/output.py @@ -205,7 +205,7 @@ def print_acct_list(accounts): def print_user_list(users): for user in users: - print_out(f"{user}") + print_out(f"* {user}") def print_tag_list(tags):