py3: display help if no subcommand provided to manage-shard-ranges
That way we don't traceback when you just provide a DB file. At some point, py3 switched to having optional subparsers. In py37, they added a kwarg to say whether a subparser is optional or required, but for the sake of earlier versions, we have to check whether it was set manually and cannot rely on argparse doing it for us. See also: - https://bugs.python.org/issue9253 - https://github.com/python/cpython/commit/aaf6fc0 - https://bugs.python.org/issue33109 - https://github.com/python/cpython/commit/8ebf5ce Change-Id: Iac8048ad0e23ffb28b914fe880c4b6538bc41c86
This commit is contained in:
@@ -438,7 +438,7 @@ def _make_parser():
|
||||
parser.add_argument('--verbose', '-v', action='count', default=0,
|
||||
help='Increase output verbosity')
|
||||
subparsers = parser.add_subparsers(
|
||||
help='Sub-command help', title='Sub-commands')
|
||||
dest='subcommand', help='Sub-command help', title='Sub-commands')
|
||||
|
||||
# find
|
||||
find_parser = subparsers.add_parser(
|
||||
@@ -503,6 +503,15 @@ def _make_parser():
|
||||
def main(args=None):
|
||||
parser = _make_parser()
|
||||
args = parser.parse_args(args)
|
||||
if not args.subcommand:
|
||||
# On py2, subparsers are required; on py3 they are not; see
|
||||
# https://bugs.python.org/issue9253. py37 added a `required` kwarg
|
||||
# to let you control it, but prior to that, there was no choice in
|
||||
# the matter. So, check whether the destination was set and bomb
|
||||
# out if not.
|
||||
parser.print_help()
|
||||
print('\nA sub-command is required.')
|
||||
return 1
|
||||
logger = get_logger({}, name='ContainerBroker', log_to_console=True)
|
||||
broker = ContainerBroker(args.container_db, logger=logger,
|
||||
skip_commits=True)
|
||||
|
||||
Reference in New Issue
Block a user