Skip to content

Commit eaee74b

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Add a document for required options"
2 parents 5125b6f + c1a040f commit eaee74b

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

doc/source/command-options.rst

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,36 @@ An example handler in `take_action()` for `unset` action:
211211
if parsed_args.no_example_property:
212212
kwargs['example_property'] = []
213213
214+
Required Options
215+
----------------
216+
217+
Some options have no default value and the API does not allow them to be
218+
`None`, then these options are always required when users use the command
219+
to which these options belong.
220+
221+
Required options must be validated by the CLI to aviod omissions. The CLI
222+
validation may provide an error message for the user if a required option
223+
is not specified.
224+
(for example: ``error: argument --test is required``)
225+
226+
.. option:: --test
227+
228+
Test option (required)
229+
230+
Implementation
231+
~~~~~~~~~~~~~~
232+
233+
The parser declaration should look like this:
234+
235+
.. code-block:: python
236+
237+
parser.add_argument(
238+
'--test',
239+
metavar='<test>',
240+
required=True,
241+
help=_('Test option (required)'),
242+
)
243+
214244
List Command Options
215245
====================
216246

0 commit comments

Comments
 (0)