def add_plugin_parsers(subparsers): api.setup_plugins() for plugin in api.get_loaded_plugins(): args_by_version = api.get_plugin_arguments(plugin) if all(args is NotImplemented for version, args in six.iteritems(args_by_version)): continue plugin_parser = subparsers.add_parser( plugin, help=_('Image generation for the {plugin} plugin').format( plugin=plugin)) version_parsers = plugin_parser.add_subparsers( title=_("Plugin version"), dest="version", help=_("Available versions")) for version, args in six.iteritems(args_by_version): if args is NotImplemented: continue version_parser = version_parsers.add_parser( version, help=_('{plugin} version {version}').format(plugin=plugin, version=version)) for arg in args: arg_token = ("--%s" % arg.name if len(arg.name) > 1 else "-%s" % arg.name) version_parser.add_argument(arg_token, dest=arg.name, help=arg.description, default=arg.default, required=arg.required, choices=arg.choices) version_parser.set_defaults(args={arg.name for arg in args})
def add_plugin_parsers(subparsers): api.setup_plugins() for plugin in CONF.plugins: args_by_version = api.get_plugin_arguments(plugin) if all(args is NotImplemented for version, args in six.iteritems(args_by_version)): continue plugin_parser = subparsers.add_parser( plugin, help=_('Image generation for the {plugin} plugin').format( plugin=plugin)) version_parsers = plugin_parser.add_subparsers( title=_("Plugin version"), dest="version", help=_("Available versions")) for version, args in six.iteritems(args_by_version): if args is NotImplemented: continue version_parser = version_parsers.add_parser( version, help=_('{plugin} version {version}').format( plugin=plugin, version=version)) for arg in args: arg_token = ("--%s" % arg.name if len(arg.name) > 1 else "-%s" % arg.name) version_parser.add_argument(arg_token, dest=arg.name, help=arg.description, default=arg.default, required=arg.required, choices=arg.choices) version_parser.set_defaults(args={arg.name for arg in args})
def test_get_plugin_arguments(self, mock_plugins_base): api.setup_plugins() mock_plugins_base.setup_plugins.assert_called_once_with() mock_PLUGINS = mock.Mock() mock_plugins_base.PLUGINS = mock_PLUGINS mock_plugin = mock.Mock() mock_plugin.get_versions = mock.Mock(return_value=['1']) mock_plugin.get_image_arguments = mock.Mock( return_value=["Argument!"]) mock_PLUGINS.get_plugin = mock.Mock(return_value=mock_plugin) result = api.get_plugin_arguments('Plugin!') mock_plugin.get_versions.assert_called_once_with() mock_plugin.get_image_arguments.assert_called_once_with('1') self.assertEqual(result, {'1': ['Argument!']})