@@ -52,7 +52,7 @@ def split_args(args: List[str], handlers: List[str]) -> Dict[str, List[str]]:
5252 return result
5353
5454
55- def args_to_objects (args : Dict [str , List [str ]], valid_plugins : Dict [str , Plugin ], allow_global_options : bool = False ) -> List [Plugin ]:
55+ def args_to_objects (args : Dict [str , List [str ]], valid_plugins : Dict [str , Plugin ], allow_global_options : bool = False , allow_unknown_args : bool = False ) -> List [Plugin ]:
5656 """
5757 Instantiates the plugins from the parsed arguments dictionary.
5858
@@ -62,6 +62,8 @@ def args_to_objects(args: Dict[str, List[str]], valid_plugins: Dict[str, Plugin]
6262 :type valid_plugins: dict
6363 :param allow_global_options: whether global options are allowed (ie options that don't follow a plugin name)
6464 :type allow_global_options: bool
65+ :param allow_unknown_args: whether to allow unknown args (eg typos or unknown plugins)
66+ :type allow_unknown_args: bool
6567 :return: the list of instantiated plugins
6668 :rtype: list
6769 """
@@ -75,7 +77,9 @@ def args_to_objects(args: Dict[str, List[str]], valid_plugins: Dict[str, Plugin]
7577
7678 name = args [key ][0 ]
7779 plugin = copy .deepcopy (valid_plugins [name ])
78- plugin .parse_args (args [key ][1 :])
80+ unknown = plugin .parse_args (args [key ][1 :])
81+ if not allow_unknown_args and (len (unknown ) > 0 ):
82+ raise Exception ("Found unknown argument(s) for plugin '%s': %s" % (plugin .name (), str (unknown )))
7983 result .append (plugin )
8084 return result
8185
0 commit comments