REST API CLI: improve color/no-color arguments
This commit is contained in:
parent
27dbcf0066
commit
55a03c2e2b
2 changed files with 8 additions and 3 deletions
|
@ -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
|
- `-u`, `--auth-user`, user for HTTP authentication
|
||||||
- `-p`, `--auth-password`, password for HTTP authentication
|
- `-p`, `--auth-password`, password for HTTP authentication
|
||||||
- `-i`, `--insecure`, enable to ignore verifying the SSL certificate. Default disabled
|
- `-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:
|
For each subcommand `--help` shows the available arguments, try for example:
|
||||||
|
|
||||||
|
|
|
@ -418,9 +418,13 @@ if __name__ == '__main__':
|
||||||
parser.add_argument('-i', '--insecure', dest='secure', action='store_false',
|
parser.add_argument('-i', '--insecure', dest='secure', action='store_false',
|
||||||
help='Set to false to ignore verifying the SSL certificate')
|
help='Set to false to ignore verifying the SSL certificate')
|
||||||
parser.set_defaults(secure=True)
|
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')
|
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 = parser.add_subparsers(dest='command', help='sub-command --help')
|
||||||
subparsers.required = True
|
subparsers.required = True
|
||||||
|
|
Loading…
Reference in a new issue