Skip to content

Commit c1a040f

Browse files
author
Huanxuan Ao
committed
Add a document for required options
Some options are required in some commands, I think we need a document to state what should we do in this case. Change-Id: Id345ca1790e2125b333b271b74288e1a73d39ba3
1 parent 97ccb65 commit c1a040f

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)