You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Print fully-qualified subcommand name in title
- Support commands:command role for intersphinx
- Prefer fully-qualified HREF targets
Use targets like "#blah-sub-commands" as
the primary target and move historic targets
like "#Sub-commands" to secondary targets.
Preserve the older HREF, `sub-commands`, as a
secondary target. In the HTML, this becomes a span
just below the section element so that bookmarks continue
to work even after adopting the update from this commit.
Copy file name to clipboardExpand all lines: docs/usage.rst
+126-1Lines changed: 126 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,3 +1,4 @@
1
+
===========
1
2
Basic usage
2
3
===========
3
4
@@ -67,6 +68,11 @@ working dir.
67
68
68
69
That's it. Directives will render positional arguments, options and sub-commands.
69
70
71
+
.. _about-subcommands:
72
+
73
+
About Sub-Commands
74
+
==================
75
+
70
76
Sub-commands are limited to one level. But, you can always output help for subcommands separately::
71
77
72
78
.. argparse::
@@ -87,7 +93,7 @@ Nesting level is unlimited::
87
93
88
94
89
95
Other useful directives
90
-
-----------------------
96
+
=======================
91
97
92
98
:nodefault: Do not show any default values.
93
99
@@ -100,3 +106,122 @@ Other useful directives
100
106
:nodescription: Do not parse the description, which can be useful if it contains text that could be incorrectly parse as reStructuredText.
101
107
102
108
:passparser: This can be used if you don't have a function that returns an argument parser, but rather adds commands to it (`:func:` is then that function).
109
+
110
+
:idxgroups: This option is related to grouping related commands in an index.
111
+
112
+
113
+
Printing Fully Qualified Sub-Command Headings
114
+
=============================================
115
+
116
+
By default, when a command has sub-commands, such as ``fancytool install`` shown in the
117
+
:ref:`about-subcommands` section, the heading for the sub-command does not include the command name.
118
+
For instance, the the heading is **install** rather than **fancytool install**.
119
+
120
+
If you prefer to show the full command, **fancytool install**, then you can enable
121
+
the option in the ``conf.py`` for your project:
122
+
123
+
.. code-block:: python
124
+
125
+
sphinx_argparse_conf = {
126
+
"full_subcommand_name": True,
127
+
}
128
+
129
+
130
+
Indices
131
+
=======
132
+
133
+
The extension supports two types of optional indices.
134
+
The first type of index is a simple index that provides a list of all the commands in the project by fully qualified name and a link to each command.
135
+
The second type of index enables you to group related commands into groups and then provide a list of the commands and a link to each command.
136
+
By default, no index is created.
137
+
138
+
Simple Command Index
139
+
--------------------
140
+
141
+
To enable the simple command index, add the following to the project ``conf.py`` file:
142
+
143
+
.. code-block:: python
144
+
145
+
sphinx_argparse_conf = {
146
+
"build_commands_index": True,
147
+
"commands_index_in_toctree": True,
148
+
}
149
+
150
+
The first option, ``build_commands_index``, instructs the extension to create the index.
151
+
For an HTML build, the index is created with the file name ``commands-index.html`` in the output directory.
152
+
You can reference the index from other files with the ``:ref:`commands-index``` markup.
153
+
154
+
The second option, ``commands_index_in_toctree``, enables you to reference the the index in a ``toctree`` directive.
155
+
By default, you cannot reference indices generated by extensions in a ``toctree``.
156
+
When you enable this option, the extension creates a temporary file that is named ``commands-index.rst`` in the source directory of your project.
157
+
Sphinx locates the temporary file and that makes it possible to reference the file in the ``toctree``.
158
+
When the Sphinx build finishes, the extension removes the temporary file from the source directory.
159
+
160
+
Commands by Group Index
161
+
-----------------------
162
+
163
+
To enable the more complex index, add the following to the project ``conf.py`` file:
164
+
165
+
.. code-block:: python
166
+
167
+
sphinx_argparse_conf = {
168
+
"build_commands_by_group_index": True,
169
+
"commands_by_group_index_in_toctree": True,
170
+
}
171
+
172
+
Add the ``:idxgroups:`` option to the ``argparse`` directive in your documentation files.
173
+
Specify one or more groups that the command belongs to.
174
+
175
+
.. code-block:: reStructuredText
176
+
177
+
.. argparse::
178
+
:filename: ../test/sample.py
179
+
:func: parser
180
+
:prog: sample
181
+
:idxgroups: ["Basic Commands"]
182
+
183
+
For an HTML build, the index is created with the file name ``commands-by-group.html`` in the output directory.
184
+
You can cross reference the index from other files with the ``:ref:`commands-by-group``` role.
185
+
186
+
Like the simple index, the ``commands_by_group_index_in_toctree`` option enables you to reference the index in ``toctree`` directives.
"commands_by_group_index_title": "Commands by Service",
196
+
}
197
+
198
+
The ``commands_by_group_index_file_suffix`` option overrides the default index name of ``commands-by-group.html``.
199
+
The value ``commands-`` is concatenated with the value you specify.
200
+
In the preceding sample, the index file name is created as ``commands-by-service.html``.
201
+
If you specify this option, the default reference of ``:ref:`commands-by-group``` is overridden with the value that you create.
202
+
203
+
The ``commands_by_group_index_title`` option overides the default first-level heading for the file.
204
+
The default heading is "Commands by Group".
205
+
The value you specify replaces the default value.
206
+
207
+
Customizing the Indices
208
+
-----------------------
209
+
210
+
By default, indices are created with the ``domainindex.html`` template.
211
+
If you want to customize the appearance of an index, copy the default ``domainindex.html`` file for your theme to the ``_templates`` directory in your project and modify it.
212
+
213
+
If you want to customize both indices, but one template cannot accommodate both of them, you can create an additional index template, such as ``customindex.html``.
214
+
You can configure Sphinx to use the additional template for an index by modifying the ``conf.py`` for the project like the following example.
0 commit comments