From 29f78500dba1aa258e4e94e331a7a48c38ce58e2 Mon Sep 17 00:00:00 2001 From: Rui Chen Date: Fri, 23 Sep 2016 15:26:48 +0800 Subject: [PATCH] Redefine set/unset command devref Now we have some use cases about set/unset properties, try to redefine devref to find out a best and easiest solution to keep commands simple and clearly. Five use cases exist in property action, "append", "update", "remove", "clean", "override", the following rules can cover all these use cases: 1. append ==> "set --property new-key=value" 2. update ==> "set --property existed-key=new-value" 3. remove ==> "unset --property existed-key" 4. clean ==> "set --no-property" 5. clean ==> "unset --all-property" 6. override ==> "set --no-property --property new-key=value" Related blueprint support-no-property-in-aggregate and blueprint allow-overwrite-set-options. Change-Id: If86daf6989d8e0ad0dc6e590d7636be7d5203a18 --- doc/source/command-options.rst | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/doc/source/command-options.rst b/doc/source/command-options.rst index a833d1d5b7..c850b000cf 100644 --- a/doc/source/command-options.rst +++ b/doc/source/command-options.rst @@ -118,12 +118,12 @@ Some options can be repeated to build a collection of values for a property. Adding a value to the collection must be provided via the ``set`` action. Removing a value from the collection must be provided via an ``unset`` action. As a convenience, removing all values from the collection may be provided via a -``--no`` option on the ``set`` and ``unset`` actions. If both ``--no`` option -and option are specified, the values specified on the command would overwrite -the collection property instead of appending on the ``set`` action. The -``--no`` option must be part of a mutually exclusive group with the related -property option on the ``unset`` action, overwrite case don't exist in -``unset`` action. +``--no`` option on the ``set`` action and a ``--all`` option on ``unset`` +action. If both ``--no`` option and option are specified, the values specified +on the command would overwrite the collection property instead of appending on +the ``set`` action. The ``--all`` option must be part of a mutually exclusive +group with the related property option on the ``unset`` action, overwrite case +don't exist in ``unset`` action. An example behavior for ``set`` action: @@ -165,7 +165,9 @@ An example parser declaration for `set` action: '--no-example-property', dest='no_example_property', action='store_true', - help=_('Remove all example properties for this '), + help=_('Remove all example properties for this ' + '(specify both --example-property and --no-example-property' + ' to overwrite the current example properties)'), ) An example handler in `take_action()` for `set` action: @@ -194,8 +196,8 @@ An example parser declaration for `unset` action: '(repeat option to remove multiple properties)'), ) example_property_group.add_argument( - '--no-example-property', - dest='no_example_property', + '--all-example-property', + dest='all_example_property', action='store_true', help=_('Remove all example properties for this '), ) @@ -208,7 +210,7 @@ An example handler in `take_action()` for `unset` action: kwargs['example_property'] = \ list(set(resource_example_property) - \ set(parsed_args.example_property)) - if parsed_args.no_example_property: + if parsed_args.all_example_property: kwargs['example_property'] = [] Required Options