tools: Make subparser required in py3
In py3, subparser is not required by default, and we get a different
error message if the command is not complete. The CL makes subparser and
namespace subparser required to get a similar behavior when the command
is not complete.
BUG=b:154580528
TEST=bin/factory_env python3 py/tools/ovl.py
TEST=bin/factory_env python3 py/tools/ovl.py -h
TEST=bin/factory_env python3 py/tools/factory.py
TEST=bin/factory_env python3 py/tools/factory.py -h
TEST=bin/factory_env python3 py/tools/gsutil.py
TEST=bin/factory_env python3 py/tools/gsutil.py -h
TEST=bin/factory_env python3 py/probe/probe_cmdline.py
TEST=bin/factory_env python3 py/probe/probe_cmdline.py -h
TEST=bin/factory_env python3 py/utils/pygpt.py
TEST=bin/factory_env python3 py/utils/pygpt.py -h
Change-Id: Id4e66260eca1589334738ac608a391f314d836ab
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/factory/+/2747091
Reviewed-by: Yilin Yang (kerker) <kerker@chromium.org>
Tested-by: Cheng Yueh <cyueh@chromium.org>
Commit-Queue: Cheng Yueh <cyueh@chromium.org>
diff --git a/py/utils/pygpt.py b/py/utils/pygpt.py
index b2d5b05..89ecada 100755
--- a/py/utils/pygpt.py
+++ b/py/utils/pygpt.py
@@ -961,7 +961,9 @@
def DefineArgs(self, parser):
"""Defines all available commands to an argparser subparsers instance."""
- subparsers = parser.add_subparsers(help='Sub-command help.', dest='command')
+ subparsers = parser.add_subparsers(title='subcommands',
+ help='Sub-command help.', dest='command')
+ subparsers.required = True
for name, instance in sorted(self.commands.items()):
parser = subparsers.add_parser(
name, description=instance.__doc__,