Skip to content

Commit 3085d03

Browse files
committed
Revise and expand CLI documentation guide
1 parent 31344c2 commit 3085d03

1 file changed

Lines changed: 87 additions & 29 deletions

File tree

user_guide/07-cli-documentation.qmd

Lines changed: 87 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,15 @@ tags: [CLI, Content]
77

88
# CLI Documentation
99

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.
1119

1220
## Enabling CLI Documentation
1321

@@ -18,26 +26,35 @@ cli:
1826
enabled: true
1927
```
2028

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.
2232

2333
## How It Works
2434

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
2643

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.
3246

3347
## Auto-Discovery
3448

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:
3651

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.
4158

4259
### Entry Point Detection
4360

@@ -52,7 +69,8 @@ Great Docs uses `my-cli` as the command name in documentation.
5269

5370
## Explicit Configuration
5471

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`:
5674

5775
```{.yaml filename="great-docs.yml"}
5876
cli:
@@ -61,8 +79,16 @@ cli:
6179
name: app # Name of the Click command object
6280
```
6381

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+
6487
## Generated Output
6588

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+
6692
### Sidebar Structure
6793

6894
CLI commands appear in the Reference sidebar:
@@ -102,12 +128,22 @@ The styling mimics a terminal with:
102128
- Monospace font
103129
- Proper spacing for readability
104130

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+
105135
## Writing Good CLI Help
106136

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.
108140

109141
### Use Descriptive Help Text
110142

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
145+
reference page:
146+
111147
```{.python filename="cli.py"}
112148
@click.command()
113149
@click.argument("path")
@@ -126,6 +162,9 @@ def build(path, output, verbose):
126162

127163
### Document All Options
128164

165+
Every `@click.option()` should include a `help=` string. Options without help text appear in the
166+
reference page but give readers no indication of what they do:
167+
129168
```{.python filename="cli.py"}
130169
@click.option(
131170
"--format",
@@ -137,6 +176,9 @@ def build(path, output, verbose):
137176

138177
### Use Click Groups for Subcommands
139178

179+
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+
140182
```{.python filename="cli.py"}
141183
@click.group()
142184
def cli():
@@ -154,9 +196,13 @@ def build():
154196
...
155197
```
156198

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+
157202
## Example: Great Docs CLI
158203

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:
160206

161207
**Main command (`great-docs`):**
162208

@@ -193,25 +239,35 @@ Options:
193239
--help Show this message and exit.
194240
```
195241

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+
196246
## Styling
197247

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
199254

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.
204257

205258
## Troubleshooting
206259

260+
If CLI documentation isn't working as expected, here are the most common issues and how to resolve
261+
them.
262+
207263
### CLI Not Detected
208264

209265
If your CLI isn't found:
210266

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:
215271

216272
```{.yaml filename="great-docs.yml"}
217273
cli:
@@ -224,13 +280,15 @@ cli:
224280

225281
If commands show minimal help:
226282

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
230286

231287
## Next Steps
232288

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.
234292

235293
- [User Guides](user-guides.qmd) explains how to add narrative documentation
236294
- [Deployment](deployment.qmd) covers publishing to GitHub Pages

0 commit comments

Comments
 (0)