From 47b182a05b02b9c56386ebf77dba702c9db6f0da Mon Sep 17 00:00:00 2001 From: Daniel Schwarz Date: Sun, 26 Mar 2023 19:23:54 -0400 Subject: [PATCH] Changed parameters for list cmds Title is now a positional parameter. Also added some error handling in the command processing for looking up list IDs per @ihabunek 's suggestions --- toot/commands.py | 34 ++++++++++++++++++---------------- toot/console.py | 35 ++++++++++++++++++----------------- 2 files changed, 36 insertions(+), 33 deletions(-) diff --git a/toot/commands.py b/toot/commands.py index 7ea29d9..b7a74c7 100644 --- a/toot/commands.py +++ b/toot/commands.py @@ -430,8 +430,12 @@ def lists(app, user, args): def list_accounts(app, user, args): - id = args.id if args.id else api.find_list_id(app, user, args.title) - response = api.get_list_accounts(app, user, id) + list_id = args.id if args.id else api.find_list_id(app, user, args.title) + if not list_id: + print_out("List not found") + return + + response = api.get_list_accounts(app, user, list_id) print_list_accounts(response) @@ -441,12 +445,16 @@ def list_create(app, user, args): def list_delete(app, user, args): - id = args.id if args.id else api.find_list_id(app, user, args.title) - api.delete_list(app, user, id) + list_id = args.id if args.id else api.find_list_id(app, user, args.title) + if not list_id: + print_out("List not found") + return + + api.delete_list(app, user, list_id) print_out(f"✓ List \"{args.title if args.title else args.id}\" deleted.") -def list_add_account(app, user, args): +def list_add(app, user, args): list_id = args.id if args.id else api.find_list_id(app, user, args.title) if not list_id: print_out("List not found") @@ -455,14 +463,11 @@ def list_add_account(app, user, args): if not account: print_out("Account not found") return - try: - api.add_accounts_to_list(app, user, list_id, [account['id']]) - print_out(f"✓ Added account \"{args.account}\"") - except Exception as ex: - print_out(f"{ex}") + api.add_accounts_to_list(app, user, list_id, [account['id']]) + print_out(f"✓ Added account \"{args.account}\"") -def list_remove_account(app, user, args): +def list_remove(app, user, args): list_id = args.id if args.id else api.find_list_id(app, user, args.title) if not list_id: print_out("List not found") @@ -471,11 +476,8 @@ def list_remove_account(app, user, args): if not account: print_out("Account not found") return - try: - api.remove_accounts_from_list(app, user, list_id, [account['id']]) - print_out(f"✓ Removed account \"{args.account}\"") - except Exception as ex: - print_out(f"{ex}") + api.remove_accounts_from_list(app, user, list_id, [account['id']]) + print_out(f"✓ Removed account \"{args.account}\"") def mute(app, user, args): diff --git a/toot/console.py b/toot/console.py index 5583fe0..5c84d97 100644 --- a/toot/console.py +++ b/toot/console.py @@ -734,12 +734,14 @@ LIST_COMMANDS = [ Command( name="list_accounts", description="List the accounts in a list", - arguments=[(["--id"], { - "type": str, - "help": "ID of the list" - }), - (["--title"], { + arguments=[ + (["--id"], { "type": str, + "help": "ID of the list" + }), + (["title"], { + "type": str, + "nargs": "?", "help": "title of the list" }), ], @@ -749,11 +751,7 @@ LIST_COMMANDS = [ name="list_create", description="Create a list", arguments=[ - (["--id"], { - "type": str, - "help": "ID of the list" - }), - (["--title"], { + (["title"], { "type": str, "help": "title of the list" }), @@ -772,26 +770,28 @@ LIST_COMMANDS = [ "type": str, "help": "ID of the list" }), - (["--title"], { + (["title"], { "type": str, + "nargs": "?", "help": "title of the list" }), ], require_auth=True, ), Command( - name="list_add_account", + name="list_add", description="Add account to list", arguments=[ (["--id"], { "type": str, "help": "ID of the list" }), - (["--title"], { + (["title"], { "type": str, + "nargs": "?", "help": "title of the list" }), - (["--account"], { + (["account"], { "type": str, "help": "Account to add" }), @@ -799,18 +799,19 @@ LIST_COMMANDS = [ require_auth=True, ), Command( - name="list_remove_account", + name="list_remove", description="Remove account from list", arguments=[ (["--id"], { "type": str, "help": "ID of the list" }), - (["--title"], { + (["title"], { "type": str, + "nargs": "?", "help": "title of the list" }), - (["--account"], { + (["account"], { "type": str, "help": "Account to remove" }),