diff options
author | John Estabrook <jestabro@vyos.io> | 2022-07-18 12:34:29 -0500 |
---|---|---|
committer | Daniil Baturin <daniil@vyos.io> | 2022-07-19 11:02:42 -0400 |
commit | 8d8c14b53408aec3011fbf33c201fda4926248bb (patch) | |
tree | 2b0fc797e3b219140fb5fa0db2c2e7d797884ad7 /python/vyos/opmode.py | |
parent | ee5f697065eb1e50ea87bb1a6423b7533c03170a (diff) | |
download | vyos-1x-8d8c14b53408aec3011fbf33c201fda4926248bb.tar.gz vyos-1x-8d8c14b53408aec3011fbf33c201fda4926248bb.zip |
T2719: patch for general support for boolean options
Signed-off-by: Daniil Baturin <daniil@vyos.io>
Diffstat (limited to 'python/vyos/opmode.py')
-rw-r--r-- | python/vyos/opmode.py | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/python/vyos/opmode.py b/python/vyos/opmode.py index 4e68d6e03..906bd0dcb 100644 --- a/python/vyos/opmode.py +++ b/python/vyos/opmode.py @@ -62,7 +62,7 @@ def _get_arg_type(t): Doesn't work with anything else at the moment! """ if _is_optional_type(t): - t.__args__[0] + return t.__args__[0] else: return t @@ -81,12 +81,13 @@ def run(module): for opt in type_hints: th = type_hints[opt] - if _is_optional_type(th): - subparser.add_argument(f"--{opt}", type=_get_arg_type(th), default=None) - elif _get_arg_type(th) == bool: + if _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) + if _is_optional_type(th): + subparser.add_argument(f"--{opt}", type=_get_arg_type(th), default=None) + else: + subparser.add_argument(f"--{opt}", type=_get_arg_type(th), required=True) # Get options as a dict rather than a namespace, # so that we can modify it and pack for passing to functions |