class Arguments(object): """ Provides a wrapper around a list of :class:`Argument`. For example .. code-block:: python class PluginExample(Plugin): arguments = PluginArguments( PluginArgument("username", help="The username for your account.", metavar="EMAIL", requires=["password"]), // requires the password too PluginArgument("password", sensitive=True, // should be masked in logs, etc. help="The password for your account.", metavar="PASSWORD") ) This will add the ``--plugin-username`` and ``--plugin-password`` arguments to the CLI (assuming the plugin module is ``plugin``). """ def __init__(self, *args): self.arguments = OrderedDict((arg.name, arg) for arg in args) def __iter__(self): return iter(self.arguments.values()) def get(self, name): return self.arguments.get(name) def requires(self, name): """ Find all the arguments required by name :param name: name of the argument the find the dependencies :return: list of dependant arguments """ results = {name} argument = self.get(name) for reqname in argument.requires: required = self.get(reqname) if not required: raise KeyError( "{0} is not a valid argument for this plugin".format( reqname)) if required.name in results: raise RuntimeError("cycle detected in plugin argument config") results.add(required.name) yield required for r in self.requires(required.name): if r.name in results: raise RuntimeError( "cycle detected in plugin argument config") results.add(r.name) yield r