From 8f86a2e1070bfd035abf047f41ee6ad8133cadba Mon Sep 17 00:00:00 2001 From: Midgard Date: Sun, 26 Sep 2021 16:43:30 +0200 Subject: [PATCH] Improve help messages --- mmcli.py | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/mmcli.py b/mmcli.py index d253388..75589d3 100755 --- a/mmcli.py +++ b/mmcli.py @@ -405,7 +405,7 @@ ENVVAR_ACCESSTOKEN = "MM_ACCESSTOKEN" def main(): prog_name = os.path.basename(sys.argv[0]) - description = "Interact with Mattermost on the CLI" + description = "Interact with Mattermost on the CLI and in scripts" epilog = f""" For further help, use `{prog_name} -h`. @@ -413,7 +413,7 @@ Where a "URL name" is required, "id:" plus an ID can also be used instead. So th town-square id:123abc456def789ghi012jkl34 -Hint: JSON output can be filtered on the command line with jq(1). +Hint: JSON output can be filtered with jq(1). """.strip() argparser = argparse.ArgumentParser( @@ -422,7 +422,7 @@ Hint: JSON output can be filtered on the command line with jq(1). ) argparser.add_argument("-i", "--ids", help="use IDs instead of names", action="store_true") argparser.add_argument( - "--format", help="output format; only json has all fields; default: json", choices=FORMATTERS, default="json") + "--format", help="output format; only json has all fields; default: %(default)s", choices=FORMATTERS, default="json") argparser.add_argument( "--server", @@ -432,9 +432,14 @@ Hint: JSON output can be filtered on the command line with jq(1). subparsers = argparser.add_subparsers(title="actions", dest="action", required=True) parser_login = subparsers.add_parser("login", help="retrieve an access token") - parser_login.add_argument("login_id", help="username or email", default=os.getenv(ENVVAR_USERNAME)) - parser_login.add_argument("--password", default=os.getenv(ENVVAR_PASSWORD)) - parser_login.add_argument("--totp", default=os.getenv(ENVVAR_TOTP)) + parser_login.add_argument( + "login_id", + help=f"username or email; envvar: {ENVVAR_USERNAME}", + default=os.getenv(ENVVAR_USERNAME)) + parser_login.add_argument( + "--password", help=f"envvar: {ENVVAR_PASSWORD}", default=os.getenv(ENVVAR_PASSWORD)) + parser_login.add_argument( + "--totp", help=f"envvar: {ENVVAR_TOTP}", default=os.getenv(ENVVAR_TOTP)) # TODO support multiple channels # parser_cat = subparsers.add_parser("cat", help="list messages in channel(s)") @@ -451,7 +456,13 @@ Hint: JSON output can be filtered on the command line with jq(1). parser_ls.add_argument("team", help="URL name of team") parser_ls.add_argument("-f", "--follow", action="store_true", help="keep running, printing changes to channels as they come in") - parser_send = subparsers.add_parser("send", help="send message(s)") + send_json_format = """ +The input format accepted on stdin is one JSON object per line. The possible fields are 'message', +'channel' (URL names of team and channel: '/'), 'channel_id' + """.strip() + parser_send = subparsers.add_parser( + "send", help="send message(s)", + epilog=send_json_format) parser_send.add_argument( "--channel", help="URL names of team and channel: '/'; if not provided, " "messages must be provided on stdin and each must specify channel")