Skip to content

Commit

Permalink
Make --verify-ssl choices explicit
Browse files Browse the repository at this point in the history
This adds true/false as explicit choices so that the help output is a
bit friendlier.

    [--verify-ssl {true, false, yes, no}]
    --verify-ssl {true, false, yes, no}
          Enable or disable the verification of the server SSL
          certificate

In CLIs with boolean flags it is also sometimes the case that you've a
``--no-*`` variant or that you can use ``no`` or something like that. So
having to pass ``false`` is not necessarily intuitive.
  • Loading branch information
mfussenegger committed Jul 8, 2019
1 parent c0334a4 commit 42bca85
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
3 changes: 3 additions & 0 deletions setup.cfg
Expand Up @@ -4,3 +4,6 @@ universal=1
[flake8]
ignore = E501,C901
exclude = tabulate.py

[pycodestyle]
ignore = E501
19 changes: 13 additions & 6 deletions src/crate/crash/command.py
Expand Up @@ -31,7 +31,7 @@
import urllib3
from getpass import getpass
from appdirs import user_data_dir, user_config_dir
from argparse import ArgumentParser
from argparse import ArgumentParser, ArgumentTypeError
from collections import namedtuple
from crate.client import connect
from crate.client.exceptions import ConnectionError, ProgrammingError
Expand Down Expand Up @@ -110,12 +110,14 @@ def parse_args(parser):


def boolean(v):
if str(v).lower() in ("yes", "true", "t", "1"):
v = str(v).lower()
if v in ("yes", "true", "t", "1"):
return True
elif str(v).lower() in ("no", "false", "f", "0"):
elif v in ("no", "false", "f", "0"):
return False
else:
raise ValueError('not a boolean value')
raise ArgumentTypeError(
'Invalid choice `{v}`, expected one of: [yes, true, t, 1, no, false, f, 0]'.format(v=v))


def get_parser(output_formats=[], conf=None):
Expand Down Expand Up @@ -160,8 +162,13 @@ def _conf_or_default(key, value):
parser.add_argument('--hosts', type=str, nargs='*',
default=_conf_or_default('hosts', ['localhost:4200']),
help='connect to HOSTS.', metavar='HOSTS')
parser.add_argument('--verify-ssl', type=boolean, default=True,
help='force the verification of the server SSL certificate')
parser.add_argument(
'--verify-ssl',
choices=(True, False),
type=boolean,
default=True,
help='Enable or disable the verification of the server SSL certificate'
)
parser.add_argument('--cert-file', type=file_with_permissions, metavar='FILENAME',
help='use FILENAME as the client certificate file')
parser.add_argument('--key-file', type=file_with_permissions, metavar='FILENAME',
Expand Down

0 comments on commit 42bca85

Please sign in to comment.