From 55a03c2e2bdbdeb1cef2d47f1f196734c4c6e2f6 Mon Sep 17 00:00:00 2001 From: Nicola Murino Date: Sun, 12 Jan 2020 14:54:41 +0100 Subject: [PATCH] REST API CLI: improve color/no-color arguments --- scripts/README.md | 3 ++- scripts/sftpgo_api_cli.py | 8 ++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/scripts/README.md b/scripts/README.md index 44ccb6ed..8340f529 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -28,7 +28,8 @@ Basically there is a sub command for each REST API and the following global argu - `-u`, `--auth-user`, user for HTTP authentication - `-p`, `--auth-password`, password for HTTP authentication - `-i`, `--insecure`, enable to ignore verifying the SSL certificate. Default disabled - - `-t`, `--no-color`, disable color highligth for JSON responses. You need python pygments module 1.5 or above for this to work. Default disabled if pygments is found, enabled if not found. Please read the note at the end of this doc for colors in Windows command prompt. + - `-t`, `--no-color`, disable color highligth for JSON responses. You need python pygments module 1.5 or above for this to work. Default disabled if pygments is found and you aren't on Windows, otherwise enabled. + - `-c`, `--color`, enable color highligth for JSON responses. You need python pygments module 1.5 or above for this to work. Default enabled if `pygments` is found and you aren't on Windows, otherwise disabled. Please read the note at the end of this doc for colors in Windows command prompt. For each subcommand `--help` shows the available arguments, try for example: diff --git a/scripts/sftpgo_api_cli.py b/scripts/sftpgo_api_cli.py index 12d135b4..b9bbe7c5 100755 --- a/scripts/sftpgo_api_cli.py +++ b/scripts/sftpgo_api_cli.py @@ -418,9 +418,13 @@ if __name__ == '__main__': parser.add_argument('-i', '--insecure', dest='secure', action='store_false', help='Set to false to ignore verifying the SSL certificate') parser.set_defaults(secure=True) - parser.add_argument('-t', '--no-color', dest='no_color', action='store_true', + has_colors_default = pygments is not None and platform.system() != "Windows" + group = parser.add_mutually_exclusive_group(required=False) + group.add_argument('-t', '--no-color', dest='no_color', action='store_true', default=(not has_colors_default), help='Disable color highlight for JSON responses. You need python pygments module 1.5 or above to have highlighted output') - parser.set_defaults(no_color=(pygments is None or platform.system() == "Windows")) + group.add_argument('-c', '--color', dest='no_color', action='store_false', default=has_colors_default, + help='Enable color highlight for JSON responses. You need python pygments module 1.5 or above to have highlighted output') + parser.add_argument_group(group) subparsers = parser.add_subparsers(dest='command', help='sub-command --help') subparsers.required = True