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
Copy file name to clipboardExpand all lines: user_guide/07-cli-documentation.qmd
+87-29Lines changed: 87 additions & 29 deletions
Original file line number
Diff line number
Diff line change
@@ -7,7 +7,15 @@ tags: [CLI, Content]
7
7
8
8
# CLI Documentation
9
9
10
-
Great Docs can automatically generate reference documentation for Click-based command-line interfaces. This creates terminal-style pages showing the `--help` output for each command.
10
+
If your Python package includes a command-line interface built with
11
+
[Click](https://click.palletsprojects.com/), Great Docs can generate reference pages for it
12
+
automatically. Each command and subcommand gets its own page showing the full `--help` output in a
13
+
terminal-style format. This means your CLI documentation stays perfectly in sync with your code,
14
+
because the help text is captured directly from Click at build time.
15
+
16
+
This page covers how to enable CLI documentation, how Great Docs discovers your commands, what the
17
+
generated pages look like, and how to write CLI help text that produces clear, useful reference
18
+
pages.
11
19
12
20
## Enabling CLI Documentation
13
21
@@ -18,26 +26,35 @@ cli:
18
26
enabled: true
19
27
```
20
28
21
-
That's it! Great Docs will automatically discover and document your CLI.
29
+
With this single setting, Great Docs handles the rest: it finds your Click commands, captures their
30
+
help output, and generates reference pages during every build. No additional configuration is needed
31
+
for standard project layouts.
22
32
23
33
## How It Works
24
34
25
-
When CLI documentation is enabled, Great Docs:
35
+
When CLI documentation is enabled, Great Docs runs a pipeline that mirrors how it handles API
36
+
documentation: discover, extract, generate, and integrate. Here's what happens during each build:
37
+
38
+
1. **Finds your CLI**: looks for Click commands in common locations
39
+
2. **Discovers entry point**: reads `[project.scripts]` from `pyproject.toml`
40
+
3. **Extracts help text**: captures `--help` output for each command and subcommand
41
+
4. **Generates pages**: creates `.qmd` files in `reference/cli/`
42
+
5. **Updates navigation**: adds a CLI section to the sidebar
26
43
27
-
1. **Finds your CLI** – Looks for Click commands in common locations
28
-
2. **Discovers entry point** – Reads `[project.scripts]` from `pyproject.toml`
29
-
3. **Extracts help text** – Captures `--help` output for each command
30
-
4. **Generates pages** – Creates `.qmd` files in `reference/cli/`
31
-
5. **Updates navigation** – Adds CLI section to the sidebar
44
+
The pipeline runs as part of `great-docs build`, so CLI pages are always regenerated from the
45
+
current state of your code. You never need to update them manually.
32
46
33
47
## Auto-Discovery
34
48
35
-
Great Docs searches for Click commands in these locations (in order):
49
+
Most Click-based packages follow a handful of common patterns for where the CLI entry point lives.
50
+
Great Docs checks these locations automatically, so you rarely need to tell it where to look:
36
51
37
-
1. `your_package.cli` – The most common location
38
-
2. `your_package.__main__` – For `python -m your_package` support
39
-
3. `your_package.main` – Alternative location
40
-
4. Entry point module from `[project.scripts]`
52
+
1. `your_package.cli`: the most common location
53
+
2. `your_package.__main__`: for `python -m your_package` support
54
+
3. `your_package.main`: alternative location
55
+
4. entry point module from `[project.scripts]`
56
+
57
+
Great Docs tries each location in order and uses the first one that contains a Click command.
41
58
42
59
### Entry Point Detection
43
60
@@ -52,7 +69,8 @@ Great Docs uses `my-cli` as the command name in documentation.
52
69
53
70
## Explicit Configuration
54
71
55
-
For non-standard setups, specify the module and command name:
72
+
If your CLI lives in a non-standard location, or if auto-discovery picks up the wrong command
73
+
object, you can specify the module and command name explicitly in `great-docs.yml`:
56
74
57
75
```{.yaml filename="great-docs.yml"}
58
76
cli:
@@ -61,8 +79,16 @@ cli:
61
79
name: app # Name of the Click command object
62
80
```
63
81
82
+
The `module` value should be the dotted import path to the Python module containing your Click group
83
+
or command. The `name` value is the variable name of the Click command object within that module.
84
+
With explicit configuration, Great Docs skips auto-discovery entirely and goes straight to the
85
+
specified location.
86
+
64
87
## Generated Output
65
88
89
+
Once Great Docs discovers your CLI, it generates a set of reference pages that integrate into the
90
+
existing site navigation. Here's what to expect.
91
+
66
92
### Sidebar Structure
67
93
68
94
CLI commands appear in the Reference sidebar:
@@ -102,12 +128,22 @@ The styling mimics a terminal with:
102
128
- Monospace font
103
129
- Proper spacing for readability
104
130
131
+
The result is a set of browsable reference pages that feel familiar to anyone who has used `--help`
132
+
in a terminal, but with the convenience of being searchable and navigable within your documentation
133
+
site.
134
+
105
135
## Writing Good CLI Help
106
136
107
-
Great Docs displays your Click help text as-is. To get the best documentation:
137
+
The quality of your CLI documentation depends entirely on the help text you write in your Click
138
+
decorators and docstrings. Great Docs displays this text as-is, so investing in clear, descriptive
139
+
help strings pays off directly in the generated pages.
108
140
109
141
### Use Descriptive Help Text
110
142
143
+
Every Click command should have a docstring that explains what it does. The first line becomes the
144
+
short description shown in `--help` listings, and the full text appears on the command's dedicated
If your CLI has multiple commands, use a `@click.group()` to organize them. Great Docs generates a
180
+
separate page for each subcommand and links them together in the sidebar:
181
+
140
182
```{.python filename="cli.py"}
141
183
@click.group()
142
184
def cli():
@@ -154,9 +196,13 @@ def build():
154
196
...
155
197
```
156
198
199
+
Well-structured Click groups produce the clearest documentation. Each subcommand becomes its own
200
+
page, and the group's docstring serves as the overview for the CLI section.
201
+
157
202
## Example: Great Docs CLI
158
203
159
-
Great Docs itself uses this feature. Its CLI documentation shows:
204
+
Great Docs uses this feature to document its own CLI. The generated pages show how the main command
205
+
and its subcommands appear in the reference section:
160
206
161
207
**Main command (`great-docs`):**
162
208
@@ -193,25 +239,35 @@ Options:
193
239
--help Show this message and exit.
194
240
```
195
241
242
+
You can see these pages live in the Great Docs reference section. They are regenerated on every
243
+
build from the actual Click commands, so they always reflect the current set of options and
244
+
subcommands.
245
+
196
246
## Styling
197
247
198
-
CLI documentation uses special styling that:
248
+
CLI reference pages use a distinct visual treatment that sets them apart from API reference pages:
249
+
250
+
- disables the sidebar filter (CLIs are usually small)
251
+
- removes breadcrumb navigation
252
+
- uses a wider content area on large screens
253
+
- maintains responsive design on mobile
199
254
200
-
- Disables the sidebar filter (CLIs are usually small)
201
-
- Removes breadcrumb navigation
202
-
- Uses a wider content area on large screens
203
-
- Maintains responsive design on mobile
255
+
These styling choices keep CLI pages clean and focused, matching the terminal-centric nature of the
256
+
content.
204
257
205
258
## Troubleshooting
206
259
260
+
If CLI documentation isn't working as expected, here are the most common issues and how to resolve
261
+
them.
262
+
207
263
### CLI Not Detected
208
264
209
265
If your CLI isn't found:
210
266
211
-
1. Verify Click is installed
212
-
2. Check the module path is correct
213
-
3. Ensure the Click command is importable
214
-
4. Use explicit configuration:
267
+
1. verify Click is installed
268
+
2. check the module path is correct
269
+
3. ensure the Click command is importable
270
+
4. use explicit configuration:
215
271
216
272
```{.yaml filename="great-docs.yml"}
217
273
cli:
@@ -224,13 +280,15 @@ cli:
224
280
225
281
If commands show minimal help:
226
282
227
-
1. Add docstrings to your Click functions
228
-
2. Add `help=` to all options
229
-
3. Use `@click.argument()` with proper names
283
+
1. add docstrings to your Click functions
284
+
2. add `help=` to all options
285
+
3. use `@click.argument()` with proper names
230
286
231
287
## Next Steps
232
288
233
-
CLI documentation works best when your Click commands already have good help text and docstrings. Great Docs takes what you've written and turns it into browsable, searchable reference pages that stay in sync with your code.
289
+
CLI documentation works best when your Click commands already have good help text and docstrings.
290
+
Great Docs takes what you've written and turns it into browsable, searchable reference pages that
291
+
stay in sync with your code.
234
292
235
293
- [User Guides](user-guides.qmd) explains how to add narrative documentation
236
294
- [Deployment](deployment.qmd) covers publishing to GitHub Pages
0 commit comments