From 0198bd3af7cbbf367dc6d8152bc8bf535c096cfd Mon Sep 17 00:00:00 2001 From: Ivan Habunek Date: Wed, 26 Apr 2017 12:11:52 +0200 Subject: [PATCH] Group commands contextually in print_help --- README.rst | 22 ++++++++---- toot/console.py | 90 ++++++++++++++++++++++++++++++------------------- 2 files changed, 71 insertions(+), 41 deletions(-) diff --git a/README.rst b/README.rst index e16e227..e158743 100644 --- a/README.rst +++ b/README.rst @@ -36,21 +36,31 @@ Running ``toot -h`` shows the documentation for the given command. toot - a Mastodon CLI client - Usage: + Authentication: toot login Log into a Mastodon instance toot login_2fa Log in using two factor authentication (experimental) toot logout Log out, delete stored access keys toot auth Show stored credentials + + Read: toot whoami Display logged in user details - toot whois Display user details - toot post Post a status text to your timeline - toot upload Upload an image or video file + toot whois Display account details toot search Search for users or hashtags - toot follow Follow an account - toot unfollow Unfollow an account toot timeline Show recent items in your public timeline toot curses An experimental timeline app. + Post: + toot post Post a status text to your timeline + toot upload Upload an image or video file + + Accounts: + toot follow Follow an account + toot unfollow Unfollow an account + toot mute Mute an account + toot unmute Unmute an account + toot block Block an account + toot unblock Unblock an account + To get help for each command run: toot --help diff --git a/toot/console.py b/toot/console.py index 831fd78..6d1c8af 100644 --- a/toot/console.py +++ b/toot/console.py @@ -32,7 +32,7 @@ account_arg = (["account"], { }) -COMMANDS = [ +AUTH_COMMANDS = [ Command( name="login", description="Log into a Mastodon instance", @@ -57,6 +57,9 @@ COMMANDS = [ arguments=[], require_auth=False, ), +] + +READ_COMMANDS = [ Command( name="whoami", description="Display logged in user details", @@ -65,7 +68,7 @@ COMMANDS = [ ), Command( name="whois", - description="Display user details", + description="Display account details", arguments=[ (["account"], { "help": "account name or numeric ID" @@ -73,6 +76,36 @@ COMMANDS = [ ], require_auth=True, ), + Command( + name="search", + description="Search for users or hashtags", + arguments=[ + (["query"], { + "help": "the search query", + }), + (["-r", "--resolve"], { + "action": 'store_true', + "default": False, + "help": "Resolve non-local accounts", + }), + ], + require_auth=True, + ), + Command( + name="timeline", + description="Show recent items in your public timeline", + arguments=[], + require_auth=True, + ), + Command( + name="curses", + description="An experimental timeline app.", + arguments=[], + require_auth=True, + ), +] + +POST_COMMANDS = [ Command( name="post", description="Post a status text to your timeline", @@ -103,21 +136,9 @@ COMMANDS = [ ], require_auth=True, ), - Command( - name="search", - description="Search for users or hashtags", - arguments=[ - (["query"], { - "help": "the search query", - }), - (["-r", "--resolve"], { - "action": 'store_true', - "default": False, - "help": "Resolve non-local accounts", - }), - ], - require_auth=True, - ), +] + +ACCOUNTS_COMMANDS = [ Command( name="follow", description="Follow an account", @@ -166,30 +187,29 @@ COMMANDS = [ ], require_auth=True, ), - Command( - name="timeline", - description="Show recent items in your public timeline", - arguments=[], - require_auth=True, - ), - Command( - name="curses", - description="An experimental timeline app.", - arguments=[], - require_auth=True, - ), ] +COMMANDS = AUTH_COMMANDS + READ_COMMANDS + POST_COMMANDS + ACCOUNTS_COMMANDS + def print_usage(): - print(CLIENT_NAME) - print("") - print("Usage:") - max_name_len = max(len(command.name) for command in COMMANDS) - for command in COMMANDS: - print(" toot", command.name.ljust(max_name_len + 2), command.description) + groups = [ + ("Authentication", AUTH_COMMANDS), + ("Read", READ_COMMANDS), + ("Post", POST_COMMANDS), + ("Accounts", ACCOUNTS_COMMANDS), + ] + + print(CLIENT_NAME) + + for name, cmds in groups: + print("") + print(name + ":") + + for cmd in cmds: + print(" toot", cmd.name.ljust(max_name_len + 2), cmd.description) print("") print("To get help for each command run:")