@@ -44,17 +44,29 @@ Once enabled, *sphinx-click* enables automatic documentation for
44
44
``short ``
45
45
List sub-commands with short documentation.
46
46
47
+ ``complete ``
48
+ List sub-commands with short documentation, then also list them with
49
+ full documentation.
50
+
47
51
``none ``
48
52
Do not list sub-commands.
49
53
50
54
Defaults to ``short `` unless ``show-nested `` (deprecated) is set.
51
55
56
+ ``:hide-header: ``
57
+ Omit the title, description and usage example, thus only showing the
58
+ subcommands.
59
+
52
60
``:commands: ``
53
61
Document only listed commands.
54
62
55
63
``:show-nested: ``
56
64
This option is deprecated; use ``nested `` instead.
57
65
66
+ ``:post-process: ``
67
+ Add a post-processing hook that will run for each command.
68
+ See :ref: `post-processing ` for more information.
69
+
58
70
The generated documentation includes anchors for the generated commands,
59
71
their options and their environment variables using the `Sphinx standard
60
72
domain `_.
@@ -276,6 +288,43 @@ assuming the group or command in ``git.git`` is named ``cli``.
276
288
Refer to `issue #2 <https://github.com/click-contrib/sphinx-click/issues/2 >`__
277
289
for more information.
278
290
291
+ .. _post-processing :
292
+
293
+ Post-processing hook
294
+ --------------------
295
+ You can add a post-processing hook that will run for each command as its
296
+ documentation is generated. To do so, use the ``:post-process: `` option,
297
+ e.g.:
298
+
299
+ .. code-block :: rst
300
+
301
+ .. click:: module:parser
302
+ :prog: hello-world
303
+ :post-process: my_library.my_module:my_function
304
+
305
+ The function will get the command object and a list of
306
+ ``docutils.nodes.Element `` entries that were generated for it, which you
307
+ can then modify to your heart's content.
308
+
309
+ Example:
310
+
311
+ .. code-block :: python
312
+
313
+ def mark_super_user_commands (command : click.Command, nodes : List[Element]) -> None :
314
+ """ Marks all commands that start with 'su-' as super user commands."""
315
+ if nodes and len (nodes) > 0 and len (nodes[0 ].children) > 0 :
316
+ command_node = nodes[0 ]
317
+ if command.name.startswith(" su-" ):
318
+ command_title = command_node.children[0 ]
319
+ text_node: docutils.nodes.Text = command_title.children[0 ]
320
+ command_title.replace(text_node, docutils.nodes.Text(text_node.as_text() + " <-- SUPER!" ))
321
+
322
+ **Note **: The function should be specified using the module path and function
323
+ name with a colon between them, e.g. ``my_library.my_module:my_function ``.
324
+ Be sure that this is accessible when generating the documentation (e.g.
325
+ add it to the ``PYTHONPATH ``).
326
+
327
+
279
328
.. URLs
280
329
281
330
.. _Sphinx directive : http://www.sphinx-doc.org/en/stable/extdev/markupapi.html
0 commit comments