@@ -112,8 +112,26 @@ Some options can be repeated to build a collection of values for a property.
112112Adding a value to the collection must be provided via the ``set `` action.
113113Removing a value from the collection must be provided via an ``unset `` action.
114114As a convenience, removing all values from the collection may be provided via a
115- ``--no `` option on the ``set `` and ``unset `` actions. The ``--no `` option must
116- be part of a mutually exclusive group with the related property option.
115+ ``--no `` option on the ``set `` and ``unset `` actions. If both ``--no `` option
116+ and option are specified, the values specified on the command would overwrite
117+ the collection property instead of appending on the ``set `` action. The
118+ ``--no `` option must be part of a mutually exclusive group with the related
119+ property option on the ``unset `` action, overwrite case don't exist in
120+ ``unset `` action.
121+
122+ An example behavior for ``set `` action:
123+
124+ Append:
125+
126+ .. code-block :: bash
127+
128+ object set --example-property xxx
129+
130+ Overwrite:
131+
132+ .. code-block :: bash
133+
134+ object set --no-example-property --example-property xxx
117135
118136 The example below assumes a property that contains a list of unique values.
119137However, this example can also be applied to other collections using the
@@ -129,16 +147,15 @@ An example parser declaration for `set` action:
129147
130148.. code-block :: python
131149
132- example_property_group = parser.add_mutually_exclusive_group()
133- example_property_group.add_argument(
150+ parser.add_argument(
134151 ' --example-property' ,
135152 metavar = ' <example-property>' ,
136153 dest = ' example_property' ,
137154 action = ' append' ,
138155 help = _(' Example property for this <resource> '
139156 ' (repeat option to set multiple properties)' ),
140157 )
141- example_property_group .add_argument(
158+ parser .add_argument(
142159 ' --no-example-property' ,
143160 dest = ' no_example_property' ,
144161 action = ' store_true' ,
@@ -149,10 +166,12 @@ An example handler in `take_action()` for `set` action:
149166
150167.. code-block :: python
151168
152- if parsed_args.example_property:
169+ if parsed_args.example_property and parsed_args.no_example_property:
170+ kwargs[' example_property' ] = parsed_args.example_property
171+ elif parsed_args.example_property:
153172 kwargs[' example_property' ] = \
154173 resource_example_property + parsed_args.example_property
155- if parsed_args.no_example_property:
174+ elif parsed_args.no_example_property:
156175 kwargs[' example_property' ] = []
157176
158177 An example parser declaration for `unset ` action:
0 commit comments