@@ -21,8 +21,6 @@ class HelpfulSubparserAction(argparse._SubParsersAction):
2121
2222 def __init__ (self , * args , ** kwargs ) -> None :
2323 super ().__init__ (* args , ** kwargs )
24- # We don't want the action self-check to kick in, so we remove the choices list, the check happens in __call__
25- self .choices = None
2624
2725 def __call__ (
2826 self ,
@@ -100,3 +98,20 @@ def _match_argument(self, action, arg_strings_pattern) -> int:
10098
10199 # return the number of arguments matched
102100 return len (match .group (1 ))
101+
102+ def _check_value (self , action : argparse .Action , value : Any ) -> None :
103+ """This is called to ensure a value is correct/valid
104+
105+ In normal operation, it would check that a value provided is valid and return None
106+ If it was not valid, it would throw an ArgumentError
107+
108+ When people provide a partial plugin name, we want to look for a matching plugin name
109+ which happens in the HelpfulSubparserAction's __call_method
110+
111+ To get there without tripping the check_value failure, we have to prevent the exception
112+ being thrown when the value is a HelpfulSubparserAction. This therefore affects no other
113+ checks for normal parameters.
114+ """
115+ if not isinstance (action , HelpfulSubparserAction ):
116+ super ()._check_value (action , value )
117+ return None
0 commit comments