From d0cfe37a7ebda848abd32fc46129e7844da5a9be Mon Sep 17 00:00:00 2001 From: Jan Cholasta Date: Jun 20 2016 14:39:12 +0000 Subject: schema: merge command args and options Rather than having args and options separately in command schema, merge them together and use new `positional` param flag to differentiate between them. https://fedorahosted.org/freeipa/ticket/4739 Reviewed-By: David Kupka --- diff --git a/VERSION b/VERSION index 24bad7f..3478231 100644 --- a/VERSION +++ b/VERSION @@ -90,5 +90,5 @@ IPA_DATA_VERSION=20100614120000 # # ######################################################## IPA_API_VERSION_MAJOR=2 -IPA_API_VERSION_MINOR=190 -# Last change: schema: remove output_params +IPA_API_VERSION_MINOR=191 +# Last change: schema: merge command args and options diff --git a/ipaclient/remote_plugins/schema.py b/ipaclient/remote_plugins/schema.py index 0ad2d25..25a2a7e 100644 --- a/ipaclient/remote_plugins/schema.py +++ b/ipaclient/remote_plugins/schema.py @@ -286,11 +286,8 @@ def _create_output(schema): def _create_command(schema): - name = str(schema['name']) - params = {m['name']: _create_param(m) for m in schema['params']} - command = {} - command['name'] = name + command['name'] = str(schema['name']) if 'doc' in schema: command['doc'] = ConcatenatedLazyText(schema['doc']) if 'topic_topic' in schema: @@ -304,9 +301,11 @@ def _create_command(schema): if 'no_cli' in schema: command['NO_CLI'] = schema['no_cli'] command['takes_args'] = tuple( - params[n] for n in schema.get('args_param', [])) + _create_param(s) for s in schema['params'] + if s.get('positional', s.get('required', True))) command['takes_options'] = tuple( - params[n] for n in schema.get('options_param', [])) + _create_param(s) for s in schema['params'] + if not s.get('positional', s.get('required', True))) command['has_output'] = tuple( _create_output(m) for m in schema['output']) diff --git a/ipaserver/plugins/schema.py b/ipaserver/plugins/schema.py index 32803a0..42806e7 100644 --- a/ipaserver/plugins/schema.py +++ b/ipaserver/plugins/schema.py @@ -176,16 +176,6 @@ class command(metaobject): label=_("Method name"), flags={'no_search'}, ), - Str( - 'args_param*', - label=_("Arguments"), - flags={'no_search'}, - ), - Str( - 'options_param*', - label=_("Options"), - flags={'no_search'}, - ), Bool( 'no_cli?', label=_("Exclude from CLI"), @@ -222,13 +212,6 @@ class command(metaobject): if cmd.NO_CLI: obj['no_cli'] = True - if len(cmd.args): - obj['args_param'] = tuple(unicode(n) for n in cmd.args) - - if len(cmd.options): - obj['options_param'] = tuple( - unicode(n) for n in cmd.options if n != 'version') - return obj def _retrieve(self, name, **kwargs): @@ -560,6 +543,11 @@ class param(BaseParam): label=_("Sensitive"), flags={'no_search'}, ), + Bool( + 'positional?', + label=_("Positional argument"), + flags={'no_search'}, + ), ) @property @@ -585,6 +573,11 @@ class param(BaseParam): obj['multivalue'] = True if param.password: obj['sensitive'] = True + if isinstance(metaobj, Command): + if param.required and param.name not in metaobj.args: + obj['positional'] = False + elif not param.required and param.name in metaobj.args: + obj['positional'] = True for key, value in param._Param__clonekw.items(): if key in ('doc',