From b8e2a0650168ce4958dc360f857c816f02c6284f Mon Sep 17 00:00:00 2001 From: Daniil Baturin Date: Tue, 5 Jul 2022 06:47:48 -0400 Subject: T2719: add general support for boolean options to generative op mode Since Python as of 3.9 doesn't give us an option to look up argument's default value by its name, this implementation requires that all boolean options must default to false. --- python/vyos/opmode.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/python/vyos/opmode.py b/python/vyos/opmode.py index 134f55017..4e68d6e03 100644 --- a/python/vyos/opmode.py +++ b/python/vyos/opmode.py @@ -81,13 +81,10 @@ def run(module): for opt in type_hints: th = type_hints[opt] - # Show commands require an option to choose between raw JSON and human-readable - # formatted output. - # For interactive use, they default to formatted output. - if _is_show(function_name) and (opt == "raw"): - subparser.add_argument(f"--raw", action='store_true') - elif _is_optional_type(th): + if _is_optional_type(th): subparser.add_argument(f"--{opt}", type=_get_arg_type(th), default=None) + elif _get_arg_type(th) == bool: + subparser.add_argument(f"--{opt}", action='store_true') else: subparser.add_argument(f"--{opt}", type=_get_arg_type(th), required=True) -- cgit v1.2.3