WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content
This repository was archived by the owner on Dec 10, 2025. It is now read-only.

Commit caf8984

Browse files
committed
Add commands to analyze and extract procedures
1 parent 1d9d34c commit caf8984

26 files changed

+5100
-14
lines changed

audit-cli/README.md

Lines changed: 271 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,14 @@ The CLI is organized into parent commands with subcommands:
5454
```
5555
audit-cli
5656
├── extract # Extract content from RST files
57-
│ └── code-examples
57+
│ ├── code-examples
58+
│ └── procedures
5859
├── search # Search through extracted content or source files
5960
│ └── find-string
6061
├── analyze # Analyze RST file structures
6162
│ ├── includes
62-
│ └── usage
63+
│ ├── usage
64+
│ └── procedures
6365
└── compare # Compare files across versions
6466
└── file-contents
6567
```
@@ -140,6 +142,111 @@ After extraction, the code extraction report shows:
140142
- Code examples by language
141143
- Code examples by directive type
142144

145+
#### `extract procedures`
146+
147+
Extract unique procedures from reStructuredText files into individual files. This command parses procedures and creates
148+
one file per unique procedure (grouped by heading and content). Each procedure file represents a distinct piece of content,
149+
even if it appears in multiple selections or variations.
150+
151+
**Use Cases:**
152+
153+
This command helps writers:
154+
- Extract all unique procedures from a page for testing or migration
155+
- Generate individual procedure files for each distinct procedure
156+
- Understand how many different procedures exist in a document
157+
- Create standalone procedure files for reuse or testing
158+
- See which selections each procedure appears in
159+
160+
**Basic Usage:**
161+
162+
```bash
163+
# Extract all unique procedures from a file
164+
./audit-cli extract procedures path/to/file.rst -o ./output
165+
166+
# Extract only procedures that appear in a specific selection
167+
./audit-cli extract procedures path/to/file.rst -o ./output --selection "driver, nodejs"
168+
169+
# Dry run (show what would be extracted without writing files)
170+
./audit-cli extract procedures path/to/file.rst -o ./output --dry-run
171+
172+
# Verbose output (shows all selections each procedure appears in)
173+
./audit-cli extract procedures path/to/file.rst -o ./output -v
174+
175+
# Expand include directives inline
176+
./audit-cli extract procedures path/to/file.rst -o ./output --expand-includes
177+
```
178+
179+
**Flags:**
180+
181+
- `-o, --output <dir>` - Output directory for extracted procedure files (default: `./output`)
182+
- `--selection <value>` - Extract only procedures that appear in a specific selection (e.g., "python", "driver, nodejs")
183+
- `--expand-includes` - Expand include directives inline instead of preserving them
184+
- `--dry-run` - Show what would be extracted without writing files
185+
- `-v, --verbose` - Show detailed processing information including all selections each procedure appears in
186+
187+
**Output Format:**
188+
189+
Extracted files are named: `{heading}-{first-step-title}-{hash}.rst`
190+
191+
The filename includes:
192+
- **Heading**: The section heading above the procedure
193+
- **First step title**: The title of the first step (for readability)
194+
- **Hash**: A short 6-character hash of the content (for uniqueness)
195+
196+
Examples:
197+
- `before-you-begin-pull-the-mongodb-docker-image-e8eeec.rst`
198+
- `install-mongodb-community-edition-download-the-tarball-44c437.rst`
199+
- `configuration-create-the-data-and-log-directories-f1d35b.rst`
200+
201+
**Verbose Output:**
202+
203+
With the `-v` flag, the command shows detailed information about each procedure:
204+
205+
```
206+
Found 36 unique procedure(s):
207+
208+
1. Before You Begin
209+
Output file: before-you-begin-pull-the-mongodb-docker-image-e8eeec.rst
210+
Steps: 5
211+
Appears in 2 selection(s):
212+
- docker, None, None, None, None, None, without-search-docker
213+
- docker, None, None, None, None, None, with-search-docker
214+
215+
2. Install MongoDB Community Edition
216+
Output file: install-mongodb-community-edition-download-the-tarball-44c437.rst
217+
Steps: 4
218+
Appears in 1 selection(s):
219+
- macos, None, None, tarball, None, None, None
220+
```
221+
222+
**Supported Procedure Types:**
223+
224+
The command recognizes and extracts:
225+
- `.. procedure::` directives with `.. step::` directives
226+
- Ordered lists (numbered or lettered) as procedures
227+
- `.. tabs::` directives with `:tabid:` options for variations
228+
- `.. composable-tutorial::` directives with `.. selected-content::` blocks
229+
- Sub-procedures (ordered lists within steps)
230+
- YAML steps files (automatically converted to RST format)
231+
232+
**How Uniqueness is Determined:**
233+
234+
Procedures are grouped by:
235+
1. **Heading**: The section heading above the procedure
236+
2. **Content hash**: A hash of the procedure's steps and content
237+
238+
This means:
239+
- Procedures with the same heading but different content are treated as separate unique procedures
240+
- Procedures with identical content that appear in multiple selections are extracted once
241+
- The output file shows all selections where that procedure appears (visible with `-v` flag)
242+
243+
**Report:**
244+
245+
After extraction, the report shows:
246+
- Number of unique procedures extracted
247+
- Number of files written
248+
- Detailed list of procedures with step counts and selections (with `-v` flag)
249+
143250
### Search Commands
144251

145252
#### `search find-string`
@@ -515,6 +622,151 @@ include : 3 files, 4 usages
515622
./audit-cli analyze usage ~/docs/source/includes/fact.rst --exclude "*/deprecated/*"
516623
```
517624

625+
#### `analyze procedures`
626+
627+
Analyze procedures in reStructuredText files to understand procedure complexity, uniqueness, and how they appear across
628+
different selections.
629+
630+
This command parses procedures from RST files and provides statistics about:
631+
- Total number of unique procedures (grouped by heading and content)
632+
- Total number of procedure appearances across all selections
633+
- Implementation types (procedure directive vs ordered list)
634+
- Step counts for each procedure
635+
- Detection of sub-procedures (ordered lists within steps)
636+
- All selections where each procedure appears
637+
638+
**Use Cases:**
639+
640+
This command helps writers:
641+
- Understand the complexity of procedures in a document
642+
- Count how many unique procedures exist vs. how many times they appear
643+
- Identify procedures that use different implementation approaches
644+
- See which selections each procedure appears in
645+
- Plan testing coverage for procedure variations
646+
- Scope work related to procedure updates
647+
648+
**Basic Usage:**
649+
650+
```bash
651+
# Get summary count of unique procedures and total appearances
652+
./audit-cli analyze procedures path/to/file.rst
653+
654+
# Show summary with incremental reporting flags
655+
./audit-cli analyze procedures path/to/file.rst --list-summary
656+
657+
# List all unique procedures with full details
658+
./audit-cli analyze procedures path/to/file.rst --list-all
659+
660+
# Expand include directives inline before analyzing
661+
./audit-cli analyze procedures path/to/file.rst --expand-includes
662+
```
663+
664+
**Flags:**
665+
666+
- `--list-summary` - Show summary statistics plus a list of procedure headings
667+
- `--list-all` - Show full details for each procedure including steps, selections, and implementation
668+
- `--expand-includes` - Expand include directives inline instead of preserving them
669+
670+
**Output:**
671+
672+
**Default output (summary only):**
673+
```
674+
File: path/to/file.rst
675+
Total unique procedures: 36
676+
Total procedure appearances: 93
677+
```
678+
679+
**With `--list-summary`:**
680+
```
681+
File: path/to/file.rst
682+
Total unique procedures: 36
683+
Total procedure appearances: 93
684+
685+
Unique Procedures:
686+
1. Before You Begin
687+
2. Install MongoDB Community Edition
688+
3. Configuration
689+
4. Run MongoDB Community Edition
690+
...
691+
```
692+
693+
**With `--list-all`:**
694+
```
695+
File: path/to/file.rst
696+
Total unique procedures: 36
697+
Total procedure appearances: 93
698+
699+
================================================================================
700+
Procedure Details
701+
================================================================================
702+
703+
1. Before You Begin
704+
Line: 45
705+
Implementation: procedure-directive
706+
Steps: 5
707+
Contains sub-procedures: no
708+
Appears in 2 selection(s):
709+
- docker, None, None, None, None, None, without-search-docker
710+
- docker, None, None, None, None, None, with-search-docker
711+
712+
Steps:
713+
1. Pull the MongoDB Docker Image
714+
2. Run the MongoDB Docker Container
715+
3. Verify MongoDB is Running
716+
4. Connect to MongoDB
717+
5. Stop the MongoDB Docker Container
718+
719+
2. Install MongoDB Community Edition
720+
Line: 123
721+
Implementation: ordered-list
722+
Steps: 4
723+
Contains sub-procedures: yes
724+
Appears in 10 selection(s):
725+
- linux, None, None, tarball, None, None, with-search
726+
- linux, None, None, tarball, None, None, without-search
727+
...
728+
729+
Steps:
730+
1. Download the tarball
731+
2. Extract the files from the tarball
732+
3. Ensure the binaries are in a directory listed in your PATH
733+
4. Run MongoDB Community Edition
734+
```
735+
736+
**Understanding the Counts:**
737+
738+
The command reports two key metrics:
739+
740+
1. **Total unique procedures**: Number of distinct procedures (grouped by heading and content hash)
741+
- Procedures with the same heading but different content are counted separately
742+
- Procedures with identical content are counted once, even if they appear in multiple selections
743+
744+
2. **Total procedure appearances**: Total number of times procedures appear across all selections
745+
- If a procedure appears in 5 different selections, it contributes 5 to this count
746+
- This represents the total number of procedure instances a user might encounter
747+
748+
**Example:**
749+
- A file might have **36 unique procedures** that appear a total of **93 times** across different selections
750+
- This means some procedures appear in multiple selections (e.g., a "Before You Begin" procedure that's the same for Docker with and without search)
751+
752+
**Supported Procedure Types:**
753+
754+
The command recognizes:
755+
- `.. procedure::` directives with `.. step::` directives
756+
- Ordered lists (numbered or lettered) as procedures
757+
- `.. tabs::` directives with `:tabid:` options for variations
758+
- `.. composable-tutorial::` directives with `.. selected-content::` blocks
759+
- Sub-procedures (ordered lists within steps)
760+
- YAML steps files (automatically converted to RST format)
761+
762+
**Deterministic Parsing:**
763+
764+
The parser ensures deterministic results by:
765+
- Sorting all map iterations to ensure consistent ordering
766+
- Sorting procedures by line number
767+
- Computing content hashes in a consistent manner
768+
- This guarantees the same file will always produce the same counts and groupings
769+
518770
### Compare Commands
519771

520772
#### `compare file-contents`
@@ -686,14 +938,19 @@ audit-cli/
686938
├── commands/ # Command implementations
687939
│ ├── extract/ # Extract parent command
688940
│ │ ├── extract.go # Parent command definition
689-
│ │ └── code-examples/ # Code examples subcommand
690-
│ │ ├── code_examples.go # Command logic
691-
│ │ ├── code_examples_test.go # Tests
692-
│ │ ├── parser.go # RST directive parsing
693-
│ │ ├── writer.go # File writing logic
694-
│ │ ├── report.go # Report generation
695-
│ │ ├── types.go # Type definitions
696-
│ │ └── language.go # Language normalization
941+
│ │ ├── code-examples/ # Code examples subcommand
942+
│ │ │ ├── code_examples.go # Command logic
943+
│ │ │ ├── code_examples_test.go # Tests
944+
│ │ │ ├── parser.go # RST directive parsing
945+
│ │ │ ├── writer.go # File writing logic
946+
│ │ │ ├── report.go # Report generation
947+
│ │ │ ├── types.go # Type definitions
948+
│ │ │ └── language.go # Language normalization
949+
│ │ └── procedures/ # Procedures extraction subcommand
950+
│ │ ├── procedures.go # Command logic
951+
│ │ ├── parser.go # Procedure parsing and filtering
952+
│ │ ├── writer.go # RST file writing
953+
│ │ └── types.go # Type definitions
697954
│ ├── search/ # Search parent command
698955
│ │ ├── search.go # Parent command definition
699956
│ │ └── find-string/ # Find string subcommand
@@ -707,6 +964,9 @@ audit-cli/
707964
│ │ │ ├── analyzer.go # Include tree building
708965
│ │ │ ├── output.go # Output formatting
709966
│ │ │ └── types.go # Type definitions
967+
│ │ ├── procedures/ # Procedures analysis subcommand
968+
│ │ │ ├── procedures.go # Command logic
969+
│ │ │ └── output.go # Output formatting
710970
│ │ └── usage/ # Usage analysis subcommand
711971
│ │ ├── usage.go # Command logic
712972
│ │ ├── usage_test.go # Tests
@@ -734,6 +994,7 @@ audit-cli/
734994
│ ├── parser.go # Generic parsing with includes
735995
│ ├── include_resolver.go # Include directive resolution
736996
│ ├── directive_parser.go # Directive parsing
997+
│ ├── procedure_parser.go # Procedure parsing (core logic)
737998
│ └── file_utils.go # File utilities
738999
└── testdata/ # Test fixtures
7391000
├── input-files/ # Test RST files

audit-cli/commands/analyze/analyze.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44
// Currently supports:
55
// - includes: Analyze include directive relationships in RST files
66
// - usage: Find all files that use a target file
7+
// - procedures: Analyze procedure variations and statistics
78
//
89
// Future subcommands could include analyzing cross-references, broken links, or content metrics.
910
package analyze
1011

1112
import (
1213
"github.com/mongodb/code-example-tooling/audit-cli/commands/analyze/includes"
14+
"github.com/mongodb/code-example-tooling/audit-cli/commands/analyze/procedures"
1315
"github.com/mongodb/code-example-tooling/audit-cli/commands/analyze/usage"
1416
"github.com/spf13/cobra"
1517
)
@@ -27,13 +29,15 @@ func NewAnalyzeCommand() *cobra.Command {
2729
Currently supports:
2830
- includes: Analyze include directive relationships (forward dependencies)
2931
- usage: Find all files that use a target file (reverse dependencies)
32+
- procedures: Analyze procedure variations and statistics
3033
3134
Future subcommands may support analyzing cross-references, broken links, or content metrics.`,
3235
}
3336

3437
// Add subcommands
3538
cmd.AddCommand(includes.NewIncludesCommand())
3639
cmd.AddCommand(usage.NewUsageCommand())
40+
cmd.AddCommand(procedures.NewProceduresCommand())
3741

3842
return cmd
3943
}

0 commit comments

Comments
 (0)