|
17 | 17 | import argparse
|
18 | 18 |
|
19 | 19 |
|
| 20 | +class ActionNoYes(argparse.Action): |
| 21 | + def __init__(self, option_strings, dest, default=None, required=False, help=None): |
| 22 | + |
| 23 | + if default is None: |
| 24 | + raise ValueError('you must provide a default with yes/no action') |
| 25 | + if len(option_strings) != 1: |
| 26 | + raise ValueError('only single argument is allowed with yes/no action') |
| 27 | + opt = option_strings[0] |
| 28 | + if not opt.startswith('--'): |
| 29 | + raise ValueError('yes/no arguments must be prefixed with --') |
| 30 | + |
| 31 | + opt = opt[2:] |
| 32 | + opts = ['--' + opt, '--no-' + opt] |
| 33 | + super(ActionNoYes, self).__init__(opts, dest, nargs=0, const=None, |
| 34 | + default=default, required=required, help=help) |
| 35 | + |
| 36 | + def __call__(self, parser, namespace, values, option_strings=None): |
| 37 | + if option_strings.startswith('--no-'): |
| 38 | + setattr(namespace, self.dest, False) |
| 39 | + else: |
| 40 | + setattr(namespace, self.dest, True) |
| 41 | + |
| 42 | + |
20 | 43 | def resolve_py_path(path):
|
21 | 44 | import os
|
22 | 45 | if not os.path.exists(path):
|
@@ -54,7 +77,8 @@ def set_base_parser():
|
54 | 77 | 'It enables large-scale index and semantic search for text-to-text, image-to-image, '
|
55 | 78 | 'video-to-video and any content form. Visit %s for tutorials and documentations.' % (
|
56 | 79 | colored('GNES v%s: Generic Neural Elastic Search' % __version__, 'green'),
|
57 |
| - colored('https://gnes.ai', 'cyan', attrs=['underline']))) |
| 80 | + colored('https://gnes.ai', 'cyan', attrs=['underline'])), |
| 81 | + formatter_class=argparse.ArgumentDefaultsHelpFormatter) |
58 | 82 | parser.add_argument('-v', '--version', action='version', version='%(prog)s ' + __version__)
|
59 | 83 | parser.add_argument('--verbose', action='store_true', default=False,
|
60 | 84 | help='turn on detailed logging for debug')
|
@@ -152,7 +176,7 @@ def set_service_parser(parser=None):
|
152 | 176 | parser.add_argument('--parallel_type', type=ParallelType.from_string, choices=list(ParallelType),
|
153 | 177 | default=ParallelType.PUSH_NONBLOCK,
|
154 | 178 | help='parallel type of the concurrent services')
|
155 |
| - parser.add_argument('--check_version', action='store_true', default=False, |
| 179 | + parser.add_argument('--check_version', action=ActionNoYes, default=True, |
156 | 180 | help='comparing the GNES and proto version of incoming message with local setup, '
|
157 | 181 | 'mismatch raise an exception')
|
158 | 182 | parser.add_argument('--identity', type=str, default=str(uuid.uuid4()).split('-')[0],
|
@@ -283,7 +307,7 @@ def set_frontend_parser(parser=None):
|
283 | 307 | read_only=True)
|
284 | 308 | parser.add_argument('--max_concurrency', type=int, default=10,
|
285 | 309 | help='maximum concurrent connections allowed')
|
286 |
| - parser.add_argument('--show_route_table', action='store_true', default=False, |
| 310 | + parser.add_argument('--route_table', action=ActionNoYes, default=True, |
287 | 311 | help='showing a route table with time cost after receiving the result')
|
288 | 312 | return parser
|
289 | 313 |
|
|
0 commit comments