Skip to content

Commit a9daecc

Browse files
authored
docs(cli): improve docstring formatting for --help and markdown (#1210)
* docs(cli): improve docstring formatting for --help and markdown - Add backticks around technical terms (APP_TARGET, APP_FLOW_SPECIFIER, paths, modules) - Fix docstring formatting in cli.py for better rendering in both terminal and markdown - Simplify extract_description() logic in generate_cli_docs.py (join with \n, let Markdown handle formatting) - Fix bullet list formatting: each bullet now on separate line - Eliminate redundant blank lines that break sentences mid-paragraph - Ensure consistent, professional rendering across all CLI commands Fixes #1108 * refactor: simplify blank line handling in extract_description Remove unnecessary last_was_empty tracking logic. Click's help formatter already produces well-formatted output, so we only need to: - Append non-empty stripped lines - Preserve blank lines for paragraph separation (if we have content) This addresses reviewer feedback and makes the code cleaner and more maintainable.
1 parent e24d1e8 commit a9daecc

File tree

3 files changed

+53
-66
lines changed

3 files changed

+53
-66
lines changed

dev/generate_cli_docs.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,15 @@ def extract_description(help_text: str) -> str:
182182
continue
183183
elif line.strip() in ["Options:", "Commands:"]:
184184
break
185-
elif in_description and line.strip():
186-
description_lines.append(line.strip())
187-
188-
description = "\n\n".join(description_lines) if description_lines else ""
185+
elif in_description:
186+
stripped = line.strip()
187+
if stripped:
188+
description_lines.append(stripped)
189+
elif description_lines: # Preserve blank line only if we have content
190+
description_lines.append("")
191+
192+
# Simply join with single newline - let Markdown handle paragraph formatting naturally
193+
description = "\n".join(description_lines) if description_lines else ""
189194
return escape_html_tags(description) # Escape HTML tags for MDX compatibility
190195

191196

docs/docs/core/cli-commands.md

Lines changed: 25 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@
77
Drop the backend setup for flows.
88

99
Modes of operation:
10-
1110
1. Drop all flows defined in an app: `cocoindex drop <APP_TARGET>`
12-
1311
2. Drop specific named flows: `cocoindex drop <APP_TARGET> [FLOW_NAME...]`
1412

13+
1514
**Usage:**
1615

1716
```bash
@@ -32,25 +31,18 @@ cocoindex drop [OPTIONS] [APP_TARGET] [FLOW_NAME]...
3231
Evaluate the flow and dump flow outputs to files.
3332

3433
Instead of updating the index, it dumps what should be indexed to files.
35-
3634
Mainly used for evaluation purpose.
3735

38-
APP_FLOW_SPECIFIER: Specifies the application and optionally the target flow.
39-
40-
Can be one of the following formats:
41-
42-
- path/to/your_app.py
43-
44-
- an_installed.module_name
45-
46-
- path/to/your_app.py:SpecificFlowName
47-
48-
- an_installed.module_name:SpecificFlowName
49-
50-
:SpecificFlowName can be omitted only if the application defines a single
36+
`APP_FLOW_SPECIFIER`: Specifies the application and optionally the target flow. Can be one of the following formats:
37+
- `path/to/your_app.py`
38+
- `an_installed.module_name`
39+
- `path/to/your_app.py:SpecificFlowName`
40+
- `an_installed.module_name:SpecificFlowName`
5141

42+
`:SpecificFlowName` can be omitted only if the application defines a single
5243
flow.
5344

45+
5446
**Usage:**
5547

5648
```bash
@@ -71,13 +63,12 @@ cocoindex evaluate [OPTIONS] APP_FLOW_SPECIFIER
7163

7264
List all flows.
7365

74-
If APP_TARGET (path/to/app.py or a module) is provided, lists flows defined
66+
If `APP_TARGET` (`path/to/app.py` or a module) is provided, lists flows
67+
defined in the app and their backend setup status.
7568

76-
in the app and their backend setup status.
69+
If `APP_TARGET` is omitted, lists all flows that have a persisted setup in
70+
the backend.
7771

78-
If APP_TARGET is omitted, lists all flows that have a persisted setup in the
79-
80-
backend.
8172

8273
**Usage:**
8374

@@ -99,7 +90,8 @@ Start a HTTP server providing REST APIs.
9990

10091
It will allow tools like CocoInsight to access the server.
10192

102-
APP_TARGET: path/to/app.py or installed_module.
93+
`APP_TARGET`: `path/to/app.py` or `installed_module`.
94+
10395

10496
**Usage:**
10597

@@ -129,10 +121,10 @@ cocoindex server [OPTIONS] APP_TARGET
129121
### `setup`
130122

131123
Check and apply backend setup changes for flows, including the internal
132-
133124
storage and target (to export to).
134125

135-
APP_TARGET: path/to/app.py or installed_module.
126+
`APP_TARGET`: `path/to/app.py` or `installed_module`.
127+
136128

137129
**Usage:**
138130

@@ -154,22 +146,18 @@ cocoindex setup [OPTIONS] APP_TARGET
154146

155147
Show the flow spec and schema.
156148

157-
APP_FLOW_SPECIFIER: Specifies the application and optionally the target
158-
149+
`APP_FLOW_SPECIFIER`: Specifies the application and optionally the target
159150
flow. Can be one of the following formats:
160151

161-
- path/to/your_app.py
162-
163-
- an_installed.module_name
164-
165-
- path/to/your_app.py:SpecificFlowName
166-
167-
- an_installed.module_name:SpecificFlowName
168-
169-
:SpecificFlowName can be omitted only if the application defines a single
152+
- `path/to/your_app.py`
153+
- `an_installed.module_name`
154+
- `path/to/your_app.py:SpecificFlowName`
155+
- `an_installed.module_name:SpecificFlowName`
170156

157+
`:SpecificFlowName` can be omitted only if the application defines a single
171158
flow.
172159

160+
173161
**Usage:**
174162

175163
```bash
@@ -190,9 +178,9 @@ cocoindex show [OPTIONS] APP_FLOW_SPECIFIER
190178

191179
Update the index to reflect the latest data from data sources.
192180

193-
APP_FLOW_SPECIFIER: path/to/app.py, module, path/to/app.py:FlowName, or
181+
`APP_FLOW_SPECIFIER`: `path/to/app.py`, module, `path/to/app.py:FlowName`,
182+
or `module:FlowName`. If `:FlowName` is omitted, updates all flows.
194183

195-
module:FlowName. If :FlowName is omitted, updates all flows.
196184

197185
**Usage:**
198186

python/cocoindex/cli.py

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,9 @@ def ls(app_target: str | None) -> None:
136136
"""
137137
List all flows.
138138
139-
If APP_TARGET (path/to/app.py or a module) is provided, lists flows
140-
defined in the app and their backend setup status.
139+
If `APP_TARGET` (`path/to/app.py` or a module) is provided, lists flows defined in the app and their backend setup status.
141140
142-
If APP_TARGET is omitted, lists all flows that have a persisted
143-
setup in the backend.
141+
If `APP_TARGET` is omitted, lists all flows that have a persisted setup in the backend.
144142
"""
145143
persisted_flow_names = flow_names_with_setup()
146144
if app_target:
@@ -188,16 +186,15 @@ def show(app_flow_specifier: str, color: bool, verbose: bool) -> None:
188186
"""
189187
Show the flow spec and schema.
190188
191-
APP_FLOW_SPECIFIER: Specifies the application and optionally the target flow.
192-
Can be one of the following formats:
189+
`APP_FLOW_SPECIFIER`: Specifies the application and optionally the target flow. Can be one of the following formats:
193190
194191
\b
195-
- path/to/your_app.py
196-
- an_installed.module_name
197-
- path/to/your_app.py:SpecificFlowName
198-
- an_installed.module_name:SpecificFlowName
192+
- `path/to/your_app.py`
193+
- `an_installed.module_name`
194+
- `path/to/your_app.py:SpecificFlowName`
195+
- `an_installed.module_name:SpecificFlowName`
199196
200-
:SpecificFlowName can be omitted only if the application defines a single flow.
197+
`:SpecificFlowName` can be omitted only if the application defines a single flow.
201198
"""
202199
app_ref, flow_ref = _parse_app_flow_specifier(app_flow_specifier)
203200
_load_user_app(app_ref)
@@ -314,7 +311,7 @@ def setup(app_target: str, force: bool, reset: bool) -> None:
314311
"""
315312
Check and apply backend setup changes for flows, including the internal storage and target (to export to).
316313
317-
APP_TARGET: path/to/app.py or installed_module.
314+
`APP_TARGET`: `path/to/app.py` or `installed_module`.
318315
"""
319316
app_ref = _get_app_ref_from_specifier(app_target)
320317
_load_user_app(app_ref)
@@ -433,8 +430,7 @@ def update(
433430
"""
434431
Update the index to reflect the latest data from data sources.
435432
436-
APP_FLOW_SPECIFIER: path/to/app.py, module, path/to/app.py:FlowName, or module:FlowName.
437-
If :FlowName is omitted, updates all flows.
433+
`APP_FLOW_SPECIFIER`: `path/to/app.py`, module, `path/to/app.py:FlowName`, or `module:FlowName`. If `:FlowName` is omitted, updates all flows.
438434
"""
439435
app_ref, flow_name = _parse_app_flow_specifier(app_flow_specifier)
440436
_load_user_app(app_ref)
@@ -492,18 +488,16 @@ def evaluate(
492488
"""
493489
Evaluate the flow and dump flow outputs to files.
494490
495-
Instead of updating the index, it dumps what should be indexed to files.
496-
Mainly used for evaluation purpose.
491+
Instead of updating the index, it dumps what should be indexed to files. Mainly used for evaluation purpose.
497492
498493
\b
499-
APP_FLOW_SPECIFIER: Specifies the application and optionally the target flow.
500-
Can be one of the following formats:
501-
- path/to/your_app.py
502-
- an_installed.module_name
503-
- path/to/your_app.py:SpecificFlowName
504-
- an_installed.module_name:SpecificFlowName
505-
506-
:SpecificFlowName can be omitted only if the application defines a single flow.
494+
`APP_FLOW_SPECIFIER`: Specifies the application and optionally the target flow. Can be one of the following formats:
495+
- `path/to/your_app.py`
496+
- `an_installed.module_name`
497+
- `path/to/your_app.py:SpecificFlowName`
498+
- `an_installed.module_name:SpecificFlowName`
499+
500+
`:SpecificFlowName` can be omitted only if the application defines a single flow.
507501
"""
508502
app_ref, flow_ref = _parse_app_flow_specifier(app_flow_specifier)
509503
_load_user_app(app_ref)
@@ -619,7 +613,7 @@ def server(
619613
620614
It will allow tools like CocoInsight to access the server.
621615
622-
APP_TARGET: path/to/app.py or installed_module.
616+
`APP_TARGET`: `path/to/app.py` or `installed_module`.
623617
"""
624618
app_ref = _get_app_ref_from_specifier(app_target)
625619
args = (

0 commit comments

Comments
 (0)