Skip to content

Commit a4af8a7

Browse files
committed
Apply suggestions from review
1 parent a10620d commit a4af8a7

File tree

2 files changed

+124
-48
lines changed

2 files changed

+124
-48
lines changed

audit-cli/README.md

Lines changed: 116 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ The CLI is organized into parent commands with subcommands:
5555
audit-cli
5656
├── extract # Extract content from RST files
5757
│ └── code-examples
58-
├── search # Search through extracted content
58+
├── search # Search through extracted content or source files
5959
│ └── find-string
6060
├── analyze # Analyze RST file structures
6161
│ └── includes
@@ -67,7 +67,18 @@ audit-cli
6767

6868
#### `extract code-examples`
6969

70-
Extract code examples from reStructuredText files into individual files.
70+
Extract code examples from reStructuredText files into individual files. For details about what code example directives
71+
are supported and how, refer to the [Supported rST Directives - Code Example Extraction](#code-example-extraction)
72+
section below.
73+
74+
**Use Cases:**
75+
76+
This command helps writers:
77+
- Examine all the code examples that make up a specific page or section
78+
- Split out code examples into individual files for migration to test infrastructure
79+
- Report on the number of code examples by language
80+
- Report on the number of code examples by directive type
81+
- Use additional commands, such as search, to find strings within specific code examples
7182

7283
**Basic Usage:**
7384

@@ -97,8 +108,16 @@ Extract code examples from reStructuredText files into individual files.
97108
**Flags:**
98109

99110
- `-o, --output <dir>` - Output directory for extracted files (default: `./output`)
100-
- `-r, --recursive` - Recursively scan directories for RST files
101-
- `-f, --follow-includes` - Follow `.. include::` directives in RST files
111+
- `-r, --recursive` - Recursively scan directories for RST files. If you do not provide this flag, the tool will only
112+
extract code examples from the top-level RST file. If you do provide this flag, the tool will recursively scan all
113+
subdirectories for RST files and extract code examples from all files.
114+
- `-f, --follow-includes` - Follow `.. include::` directives in RST files. If you do not provide this flag, the tool
115+
will only extract code examples from the top-level RST file. If you do provide this flag, the tool will follow any
116+
`.. include::` directives in the RST file and extract code examples from all included files. When combined with `-r`,
117+
the tool will recursively scan all subdirectories for RST files and follow `.. include::` directives in all files. If
118+
an include filepath is *outside* the input directory, the `-r` flag would not parse it, but the `-f` flag would
119+
follow the include directive and parse the included file. This effectively lets you parse all the files that make up
120+
a single page, if you start from the page's root `.txt` file.
102121
- `--dry-run` - Show what would be extracted without writing files
103122
- `-v, --verbose` - Show detailed processing information
104123

@@ -114,7 +133,7 @@ Examples:
114133

115134
**Report:**
116135

117-
After extraction, a report is displayed showing:
136+
After extraction, the code extraction report shows:
118137
- Number of files traversed
119138
- Number of output files written
120139
- Code examples by language
@@ -130,7 +149,17 @@ Search through files for a specific substring. Can search through extracted code
130149
- **Case-insensitive** search (matches "curl", "CURL", "Curl", etc.)
131150
- **Exact word matching** (excludes partial matches like "curl" in "libcurl")
132151

133-
Use `--case-sensitive` to make the search case-sensitive, or `--partial-match` to allow matching the substring as part of larger words.
152+
Use `--case-sensitive` to make the search case-sensitive, or `--partial-match` to allow matching the substring as part
153+
of larger words.
154+
155+
**Use Cases:**
156+
157+
This command helps writers:
158+
- Find specific strings across documentation files or pages
159+
- Search for product names, command names, API methods, or other strings that may need to be updated
160+
- Understand the number of references and impact of changes across documentation files or pages
161+
- Identify files that need to be updated when a string needs to be changed
162+
- Scope work related to specific changes
134163

135164
**Basic Usage:**
136165

@@ -165,8 +194,16 @@ Use `--case-sensitive` to make the search case-sensitive, or `--partial-match` t
165194

166195
**Flags:**
167196

168-
- `-r, --recursive` - Recursively search all files in subdirectories
169-
- `-f, --follow-includes` - Follow `.. include::` directives in RST files
197+
- `-r, --recursive` - Recursively scan directories for RST files. If you do not provide this flag, the tool will only
198+
search within the top-level RST file or directory. If you do provide this flag, the tool will recursively scan all
199+
subdirectories for RST files and search across all files.
200+
- `-f, --follow-includes` - Follow `.. include::` directives in RST files. If you do not provide this flag, the tool
201+
will search only the top-level RST file or directory. If you do provide this flag, the tool will follow any
202+
`.. include::` directives in any RST file in the input path and search across all included files. When
203+
combined with `-r`, the tool will recursively scan all subdirectories for RST files and follow `.. include::` directives
204+
in all files. If an include filepath is *outside* the input directory, the `-r` flag would not parse it, but the `-f`
205+
flag would follow the include directive and search the included file. This effectively lets you parse all the files
206+
that make up a single page, if you start from the page's root `.txt` file.
170207
- `-v, --verbose` - Show file paths and language breakdown
171208
- `--case-sensitive` - Make search case-sensitive (default: case-insensitive)
172209
- `--partial-match` - Allow partial matches within words (default: exact word matching)
@@ -185,7 +222,15 @@ With `-v` flag, also shows:
185222

186223
#### `analyze includes`
187224

188-
Analyze include directive relationships in RST files to understand file dependencies.
225+
Analyze `include` directive relationships in RST files to understand file dependencies.
226+
227+
**Use Cases:**
228+
229+
This command helps writers:
230+
- Understand the impact of changes to widely-included files
231+
- Identify circular include dependencies (files included multiple times)
232+
- Document file relationships for maintenance
233+
- Plan refactoring of complex include structures
189234

190235
**Basic Usage:**
191236

@@ -230,17 +275,12 @@ Analyze include directive relationships in RST files to understand file dependen
230275
- Files listed in depth-first traversal order
231276
- Shows absolute paths to all files
232277

233-
**Use Cases:**
234-
235-
This command helps writers:
236-
- Understand the impact of changes to widely-included files
237-
- Identify circular include dependencies (files included multiple times)
238-
- Document file relationships for maintenance
239-
- Plan refactoring of complex include structures
240-
241278
**Note on File Counting:**
242279

243-
The total file count represents **unique files** discovered through include directives. If a file is included multiple times (e.g., file A includes file C, and file B also includes file C), it is counted only once in the total. However, the tree view will show it in all locations where it appears, with subsequent occurrences marked as circular includes in verbose mode.
280+
The total file count represents **unique files** discovered through include directives. If a file is included multiple
281+
times (e.g., file A includes file C, and file B also includes file C), the file is counted only once in the total.
282+
However, the tree view will show it in all locations where it appears, with subsequent occurrences marked as circular
283+
includes in verbose mode.
244284

245285
### Compare Commands
246286

@@ -400,7 +440,8 @@ product-dir/
400440

401441
**Note on Missing Files:**
402442

403-
Files that don't exist in certain versions are reported separately and do not cause errors. This is expected behavior since features may be added or removed across versions.
443+
Files that don't exist in certain versions are reported separately and do not cause errors. This is expected behavior
444+
since features may be added or removed across versions.
404445

405446
## Development
406447

@@ -559,8 +600,6 @@ Example: Adding `analyze` parent command
559600
}
560601
```
561602

562-
563-
564603
### Testing
565604

566605
#### Running Tests
@@ -588,7 +627,8 @@ Tests use a table-driven approach with test fixtures in the `testdata/` director
588627
- **Expected output**: `testdata/expected-output/` - Expected extracted files
589628
- **Test pattern**: Compare actual extraction output against expected files
590629

591-
**Note**: The `testdata` directory name is special in Go - it's automatically ignored during builds, which is important since it contains non-Go files (`.cpp`, `.rst`, etc.).
630+
**Note**: The `testdata` directory name is special in Go - it's automatically ignored during builds, which is important
631+
since it contains non-Go files (`.cpp`, `.rst`, etc.).
592632

593633
#### Adding New Tests
594634

@@ -634,7 +674,8 @@ Tests use a table-driven approach with test fixtures in the `testdata/` director
634674
635675
#### Test Conventions
636676
637-
- **Relative paths**: Tests use `filepath.Join("..", "..", "..", "testdata")` to reference test data (three levels up from `commands/extract/code-examples/`)
677+
- **Relative paths**: Tests use `filepath.Join("..", "..", "..", "testdata")` to reference test data (three levels up
678+
from `commands/extract/code-examples/`)
638679
- **Temporary directories**: Use `os.MkdirTemp()` for test output, clean up with `defer os.RemoveAll()`
639680
- **Exact content matching**: Tests compare byte-for-byte content
640681
- **No trailing newlines**: Expected output files should not have trailing blank lines
@@ -848,13 +889,13 @@ func processWithVerbose(filePath string, verbose bool) error {
848889
}
849890
```
850891
851-
852-
853892
## Supported RST Directives
854893
894+
### Code Example Extraction
895+
855896
The tool extracts code examples from the following reStructuredText directives:
856897
857-
### 1. `literalinclude`
898+
#### 1. `literalinclude`
858899
859900
Extracts code from external files with support for partial extraction and dedenting.
860901
@@ -899,7 +940,7 @@ result = calculate(42)
899940
print(result)
900941
```
901942
902-
### 2. `code-block`
943+
#### 2. `code-block`
903944
904945
Inline code blocks with automatic dedenting based on the first line's indentation.
905946
@@ -932,14 +973,15 @@ The content is automatically dedented based on the indentation of the first cont
932973
print("Hello")
933974
```
934975
935-
The code has 6 spaces of indentation (3 from `note`, 3 from `code-block`). The tool automatically removes these 6 spaces, resulting in:
976+
The code has 6 spaces of indentation (3 from `note`, 3 from `code-block`). The tool automatically removes these 6 spaces,
977+
resulting in:
936978
937979
```python
938980
def hello():
939981
print("Hello")
940982
```
941983
942-
### 3. `io-code-block`
984+
#### 3. `io-code-block`
943985
944986
Input/output code blocks for interactive examples with nested sub-directives.
945987
@@ -991,7 +1033,9 @@ Generates two files:
9911033
9921034
Example: `my-doc.io-code-block.1.input.js` and `my-doc.io-code-block.1.output.json`
9931035
994-
### 4. `include`
1036+
### Include handling
1037+
1038+
#### 4. `include`
9951039
9961040
Follows include directives to process entire documentation trees (when `-f` flag is used).
9971041
@@ -1004,18 +1048,18 @@ Follows include directives to process entire documentation trees (when `-f` flag
10041048
10051049
The tool handles several MongoDB-specific include patterns:
10061050
1007-
#### Steps Files
1051+
##### Steps Files
10081052
Converts directory-based paths to filename-based paths:
10091053
- Input: `/includes/steps/run-mongodb-on-linux.rst`
10101054
- Resolves to: `/includes/steps-run-mongodb-on-linux.yaml`
10111055
1012-
#### Extracts and Release Files
1056+
##### Extracts and Release Files
10131057
Resolves ref-based includes by searching YAML files:
10141058
- Input: `/includes/extracts/install-mongodb.rst`
10151059
- Searches: `/includes/extracts-*.yaml` for `ref: install-mongodb`
10161060
- Resolves to: The YAML file containing that ref
10171061
1018-
#### Template Variables
1062+
##### Template Variables
10191063
Resolves template variables from YAML replacement sections:
10201064
```yaml
10211065
replacement:
@@ -1026,7 +1070,8 @@ replacement:
10261070
10271071
**Source Directory Resolution:**
10281072
1029-
The tool walks up the directory tree to find a directory named "source" or containing a "source" subdirectory. This is used as the base for resolving relative include paths.
1073+
The tool walks up the directory tree to find a directory named "source" or containing a "source" subdirectory. This is
1074+
used as the base for resolving relative include paths.
10301075
10311076
## Internal Packages
10321077
@@ -1048,15 +1093,47 @@ The tool normalizes language identifiers to standard file extensions:
10481093
10491094
| Input | Normalized | Extension |
10501095
|-------|-----------|-----------|
1051-
| `ts` | `typescript` | `.ts` |
1096+
| `bash` | `bash` | `.sh` |
1097+
| `c` | `c` | `.c` |
10521098
| `c++` | `cpp` | `.cpp` |
1099+
| `c#` | `csharp` | `.cs` |
1100+
| `console` | `console` | `.sh` |
1101+
| `cpp` | `cpp` | `.cpp` |
1102+
| `cs` | `csharp` | `.cs` |
1103+
| `csharp` | `csharp` | `.cs` |
1104+
| `go` | `go` | `.go` |
10531105
| `golang` | `go` | `.go` |
1106+
| `java` | `java` | `.java` |
10541107
| `javascript` | `javascript` | `.js` |
1108+
| `js` | `javascript` | `.js` |
1109+
| `kotlin` | `kotlin` | `.kt` |
1110+
| `kt` | `kotlin` | `.kt` |
1111+
| `php` | `php` | `.php` |
1112+
| `powershell` | `powershell` | `.ps1` |
1113+
| `ps1` | `powershell` | `.ps1` |
1114+
| `ps5` | `ps5` | `.ps1` |
1115+
| `py` | `python` | `.py` |
10551116
| `python` | `python` | `.py` |
1056-
| `shell` / `sh` | `sh` | `.sh` |
1057-
| `json` | `json` | `.json` |
1058-
| `yaml` | `yaml` | `.yaml` |
1059-
| (none) | `txt` | `.txt` |
1117+
| `rb` | `ruby` | `.rb` |
1118+
| `rs` | `rust` | `.rs` |
1119+
| `ruby` | `ruby` | `.rb` |
1120+
| `rust` | `rust` | `.rs` |
1121+
| `scala` | `scala` | `.scala` |
1122+
| `sh` | `shell` | `.sh` |
1123+
| `shell` | `shell` | `.sh` |
1124+
| `swift` | `swift` | `.swift` |
1125+
| `text` | `text` | `.txt` |
1126+
| `ts` | `typescript` | `.ts` |
1127+
| `txt` | `text` | `.txt` |
1128+
| `typescript` | `typescript` | `.ts` |
1129+
| (empty string) | `undefined` | `.txt` |
1130+
| `none` | `undefined` | `.txt` |
1131+
| (unknown) | (unchanged) | `.txt` |
1132+
1133+
**Notes:**
1134+
- Language identifiers are case-insensitive
1135+
- Unknown languages are returned unchanged by `NormalizeLanguage()` but map to `.txt` extension
1136+
- The normalization handles common aliases (e.g., `ts` → `typescript`, `golang` → `go`, `c++` → `cpp`)
10601137
10611138
## Contributing
10621139
@@ -1067,7 +1144,3 @@ When contributing to this project:
10671144
3. **Update documentation** - Keep this README up to date with new features
10681145
4. **Run tests before committing** - Ensure `go test ./...` passes
10691146
5. **Use meaningful commit messages** - Describe what changed and why
1070-
1071-
## License
1072-
1073-
[Add license information here]

audit-cli/main.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
//
66
// The CLI is organized into parent commands with subcommands:
77
// - extract: Extract content from RST files
8-
// - code-examples: Extract code examples from RST directives
8+
// - code-examples: Extract code examples from RST directives
99
// - search: Search through extracted content
10-
// - find-string: Search for substrings in extracted files
10+
// - find-string: Search for substrings in extracted files
1111
// - analyze: Analyze RST file structures
12-
// - includes: Analyze include directive relationships
12+
// - includes: Analyze include directive relationships
1313
// - compare: Compare files across different versions
14-
// - file-contents: Compare file contents across versions
14+
// - file-contents: Compare file contents across versions
1515
package main
1616

1717
import (
@@ -39,5 +39,8 @@ with special handling for MongoDB documentation conventions.`,
3939
rootCmd.AddCommand(analyze.NewAnalyzeCommand())
4040
rootCmd.AddCommand(compare.NewCompareCommand())
4141

42-
rootCmd.Execute()
42+
err := rootCmd.Execute()
43+
if err != nil {
44+
return
45+
}
4346
}

0 commit comments

Comments
 (0)