[Feature] Optional choices (#6463)

* using the custom argument to leverage validation

* restructure

* better handling of variables and props

* optional choices

* utilities module

* proper handling of optional choices attr

* setattr

---------

Co-authored-by: Danglewood <85772166+deeleeramone@users.noreply.github.com>
Co-authored-by: Igor Radovanovic <74266147+IgorWounds@users.noreply.github.com>
This commit is contained in:
Henrique Joaquim
2024-06-04 08:57:36 +01:00
committed by GitHub
parent 8a63c2df3e
commit f860c6d797
7 changed files with 366 additions and 266 deletions

View File

@@ -807,7 +807,11 @@ class BaseController(metaclass=ABCMeta):
i + 1
for i, arg in enumerate(other_args)
if arg in ("-i", "--input")
and "routine_args" in [action.dest for action in parser._actions]
and "routine_args"
in [
action.dest
for action in parser._actions # pylint: disable=protected-access
]
),
-1,
)
@@ -818,6 +822,11 @@ class BaseController(metaclass=ABCMeta):
for part in (arg.split(",") if index != routine_args_index else [arg])
]
# Check if the action has optional choices, if yes, remove them
for action in parser._actions: # pylint: disable=protected-access
if hasattr(action, "optional_choices") and action.optional_choices:
action.choices = None
(ns_parser, l_unknown_args) = parser.parse_known_args(other_args)
if export_allowed in [