From 731bf44ceb0ca239f4fab01bd1d43018cd8fa57e Mon Sep 17 00:00:00 2001 From: Reid Priedhorsky Date: Mon, 27 Jun 2022 10:32:15 -0600 Subject: [PATCH 1/2] print grouped common option help in subcommands --- bin/ch-image.py.in | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/bin/ch-image.py.in b/bin/ch-image.py.in index 3cec79432..444cc23c0 100644 --- a/bin/ch-image.py.in +++ b/bin/ch-image.py.in @@ -79,7 +79,7 @@ def main(): # [2]: https://docs.python.org/3/library/argparse.html#parents # [3]: https://stackoverflow.com/a/54936198 common_opts = \ - { "bucache": [ + { ("bucache", "build cache common options"): [ [["--cache"], { "action": "store_const", "const": ch.Build_Mode.ENABLED, @@ -95,7 +95,7 @@ def main(): "const": ch.Build_Mode.REBUILD, "dest": "bucache", "help": "force cache misses for non-FROM instructions" }] ], - None: [ + (None, "misc common options"): [ [["-a", "--arch"], { "metavar": "ARCH", "default": "host", @@ -145,19 +145,14 @@ def main(): p.set_defaults(func=dispatch) dependencies_check[dispatch] = deps_check storage_init[dispatch] = stog_init - for (name, group) in common_opts.items(): + for ((name, title), group) in common_opts.items(): if (name is None): - p2 = p + p2 = p.add_argument_group(title=title) else: - p2 = p.add_mutually_exclusive_group() + p2 = p.add_argument_group(title=title) + p2 = p2.add_mutually_exclusive_group() for (args, kwargs) in group: - if (help_): - kwargs2 = kwargs - else: - kwargs2 = { **kwargs, - "default": argparse.SUPPRESS, - "help": argparse.SUPPRESS } - p2.add_argument(*args, **kwargs2) + p2.add_argument(*args, **kwargs) # main parser add_opts(ap, None, deps_check=False, stog_init=False, help_=True) From 8c535bb721060a9d575b0b869b6df55163929ed3 Mon Sep 17 00:00:00 2001 From: Reid Priedhorsky Date: Mon, 27 Jun 2022 10:37:18 -0600 Subject: [PATCH 2/2] restore no defaults for common options on subcommands --- bin/ch-image.py.in | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/bin/ch-image.py.in b/bin/ch-image.py.in index 444cc23c0..e91ac7db1 100644 --- a/bin/ch-image.py.in +++ b/bin/ch-image.py.in @@ -152,7 +152,11 @@ def main(): p2 = p.add_argument_group(title=title) p2 = p2.add_mutually_exclusive_group() for (args, kwargs) in group: - p2.add_argument(*args, **kwargs) + if (help_): + kwargs2 = kwargs + else: + kwargs2 = { **kwargs, "default": argparse.SUPPRESS } + p2.add_argument(*args, **kwargs2) # main parser add_opts(ap, None, deps_check=False, stog_init=False, help_=True)