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 9453fcd

Browse files
authored
Merge pull request #104 from mongodb/add-count-tested-examples-command
Audit CLI: Add new `count` command with two subcommands
2 parents 2ec5ee6 + 140da25 commit 9453fcd

File tree

48 files changed

+1930
-20
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1930
-20
lines changed

audit-cli/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
audit-cli
22
output/
3+
bin/

audit-cli/README.md

Lines changed: 223 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ A Go CLI tool for extracting and analyzing code examples from MongoDB documentat
1111
- [Search Commands](#search-commands)
1212
- [Analyze Commands](#analyze-commands)
1313
- [Compare Commands](#compare-commands)
14+
- [Count Commands](#count-commands)
1415
- [Development](#development)
1516
- [Project Structure](#project-structure)
1617
- [Adding New Commands](#adding-new-commands)
@@ -34,11 +35,11 @@ This CLI tool helps maintain code quality across MongoDB's documentation by:
3435
### Build from Source
3536

3637
```bash
37-
cd audit-cli
38-
go build
38+
cd audit-cli/bin
39+
go build ../
3940
```
4041

41-
This creates an `audit-cli` executable in the current directory.
42+
This creates an `audit-cli` executable in the `bin` directory.
4243

4344
### Run Without Building
4445

@@ -62,8 +63,12 @@ audit-cli
6263
│ ├── includes
6364
│ ├── usage
6465
│ └── procedures
65-
└── compare # Compare files across versions
66-
└── file-contents
66+
│ └── usage
67+
├── compare # Compare files across versions
68+
│ └── file-contents
69+
└── count # Count code examples and documentation pages
70+
├── tested-examples
71+
└── pages
6772
```
6873

6974
### Extract Commands
@@ -930,6 +935,188 @@ product-dir/
930935
Files that don't exist in certain versions are reported separately and do not cause errors. This is expected behavior
931936
since features may be added or removed across versions.
932937

938+
### Count Commands
939+
940+
#### `count tested-examples`
941+
942+
Count tested code examples in the MongoDB documentation monorepo.
943+
944+
This command navigates to the `content/code-examples/tested` directory from the monorepo root and counts all files recursively. The tested directory has a two-level structure: L1 (language directories) and L2 (product directories).
945+
946+
**Use Cases:**
947+
948+
This command helps writers and maintainers:
949+
- Track the total number of tested code examples
950+
- Monitor code example coverage by product
951+
- Identify products with few or many examples
952+
- Count only source files (excluding output files)
953+
954+
**Basic Usage:**
955+
956+
```bash
957+
# Get total count of all tested code examples
958+
./audit-cli count tested-examples /path/to/docs-monorepo
959+
960+
# Count examples for a specific product
961+
./audit-cli count tested-examples /path/to/docs-monorepo --for-product pymongo
962+
963+
# Show counts broken down by product
964+
./audit-cli count tested-examples /path/to/docs-monorepo --count-by-product
965+
966+
# Count only source files (exclude .txt and .sh output files)
967+
./audit-cli count tested-examples /path/to/docs-monorepo --exclude-output
968+
```
969+
970+
**Flags:**
971+
972+
- `--for-product <product>` - Only count code examples for a specific product
973+
- `--count-by-product` - Display counts for each product
974+
- `--exclude-output` - Only count source files (exclude .txt and .sh files)
975+
976+
**Current Valid Products:**
977+
978+
- `mongosh` - MongoDB Shell
979+
- `csharp/driver` - C#/.NET Driver
980+
- `go/driver` - Go Driver
981+
- `go/atlas-sdk` - Atlas Go SDK
982+
- `java/driver-sync` - Java Sync Driver
983+
- `javascript/driver` - Node.js Driver
984+
- `pymongo` - PyMongo Driver
985+
986+
**Output:**
987+
988+
By default, prints a single integer (total count) for use in CI or scripting. With `--count-by-product`, displays a formatted table with product names and counts.
989+
990+
#### `count pages`
991+
992+
Count documentation pages (.txt files) in the MongoDB documentation monorepo.
993+
994+
This command navigates to the `content` directory and recursively counts all `.txt` files, which represent documentation pages that resolve to unique URLs. The command automatically excludes certain directories and file types that don't represent actual documentation pages.
995+
996+
**Use Cases:**
997+
998+
This command helps writers and maintainers:
999+
- Track the total number of documentation pages across the monorepo
1000+
- Monitor documentation coverage by product/project
1001+
- Identify projects with extensive or minimal documentation
1002+
- Exclude auto-generated or deprecated content from counts
1003+
- Count only current versions of versioned documentation
1004+
- Compare page counts across different documentation versions
1005+
1006+
**Automatic Exclusions:**
1007+
1008+
The command automatically excludes:
1009+
- Files in `code-examples` directories at the root of `content` or `source` (these contain plain text examples, not pages)
1010+
- Files in the following directories at the root of `content`:
1011+
- `404` - Error pages
1012+
- `docs-platform` - Documentation for the MongoDB website and meta content
1013+
- `meta` - MongoDB Meta Documentation - style guide, tools, etc.
1014+
- `table-of-contents` - Navigation files
1015+
- All non-`.txt` files (configuration files, YAML, etc.)
1016+
1017+
**Basic Usage:**
1018+
1019+
```bash
1020+
# Get total count of all documentation pages
1021+
./audit-cli count pages /path/to/docs-monorepo
1022+
1023+
# Count pages for a specific project
1024+
./audit-cli count pages /path/to/docs-monorepo --for-project manual
1025+
1026+
# Show counts broken down by project
1027+
./audit-cli count pages /path/to/docs-monorepo --count-by-project
1028+
1029+
# Exclude specific directories from counting
1030+
./audit-cli count pages /path/to/docs-monorepo --exclude-dirs api-reference,generated
1031+
1032+
# Count only current versions (for versioned projects)
1033+
./audit-cli count pages /path/to/docs-monorepo --current-only
1034+
1035+
# Show counts by project and version
1036+
./audit-cli count pages /path/to/docs-monorepo --by-version
1037+
1038+
# Combine flags: count pages for a specific project, excluding certain directories
1039+
./audit-cli count pages /path/to/docs-monorepo --for-project atlas --exclude-dirs deprecated
1040+
```
1041+
1042+
**Flags:**
1043+
1044+
- `--for-project <project>` - Only count pages for a specific project (directory name under `content/`)
1045+
- `--count-by-project` - Display counts for each project in a formatted table
1046+
- `--exclude-dirs <dirs>` - Comma-separated list of directory names to exclude from counting (e.g., `deprecated,archive`)
1047+
- `--current-only` - Only count pages in the current version (for versioned projects, counts only `current` or `manual` version directories; for non-versioned projects, counts all pages)
1048+
- `--by-version` - Display counts grouped by project and version (shows version breakdown for versioned projects; non-versioned projects show as "(no version)")
1049+
1050+
**Output:**
1051+
1052+
By default, prints a single integer (total count) for use in CI or scripting. With `--count-by-project`, displays a formatted table with project names and counts. With `--by-version`, displays a hierarchical breakdown by project and version.
1053+
1054+
**Versioned Documentation:**
1055+
1056+
Some MongoDB documentation projects contain multiple versions, represented as distinct directories between the project directory and the `source` directory:
1057+
- **Versioned project structure**: `content/{project}/{version}/source/...`
1058+
- **Non-versioned project structure**: `content/{project}/source/...`
1059+
1060+
Version directory names follow these patterns:
1061+
- `current` or `manual` - The current/latest version
1062+
- `upcoming` - Pre-release version
1063+
- `v{number}` - Specific version (e.g., `v8.0`, `v7.0`)
1064+
1065+
The `--current-only` flag counts only files in the current version directory (`current` or `manual`) for versioned projects, while counting all files for non-versioned projects.
1066+
1067+
The `--by-version` flag shows a breakdown of page counts for each version within each project.
1068+
1069+
**Note:** The `--current-only` and `--by-version` flags are mutually exclusive.
1070+
1071+
**Examples:**
1072+
1073+
```bash
1074+
# Quick count for CI/CD
1075+
TOTAL_PAGES=$(./audit-cli count pages ~/docs-monorepo)
1076+
echo "Total documentation pages: $TOTAL_PAGES"
1077+
1078+
# Detailed breakdown by project
1079+
./audit-cli count pages ~/docs-monorepo --count-by-project
1080+
# Output:
1081+
# Page Counts by Project:
1082+
#
1083+
# app-services 245
1084+
# atlas 512
1085+
# manual 1024
1086+
# ...
1087+
#
1088+
# Total: 2891
1089+
1090+
# Count only Atlas pages
1091+
./audit-cli count pages ~/docs-monorepo --for-project atlas
1092+
# Output: 512
1093+
1094+
# Exclude deprecated content
1095+
./audit-cli count pages ~/docs-monorepo --exclude-dirs deprecated,archive --count-by-project
1096+
1097+
# Count only current versions
1098+
./audit-cli count pages ~/docs-monorepo --current-only
1099+
# Output: 1245 (only counts current/manual versions)
1100+
1101+
# Show breakdown by version
1102+
./audit-cli count pages ~/docs-monorepo --by-version
1103+
# Output:
1104+
# Project: drivers
1105+
# manual 150
1106+
# upcoming 145
1107+
# v8.0 140
1108+
# v7.0 135
1109+
#
1110+
# Project: atlas
1111+
# (no version) 200
1112+
#
1113+
# Total: 770
1114+
1115+
# Count current version for a specific project
1116+
./audit-cli count pages ~/docs-monorepo --for-project drivers --current-only
1117+
# Output: 150
1118+
```
1119+
9331120
## Development
9341121

9351122
### Project Structure
@@ -979,16 +1166,30 @@ audit-cli/
9791166
│ │ ├── analyzer.go # Reference finding logic
9801167
│ │ ├── output.go # Output formatting
9811168
│ │ └── types.go # Type definitions
982-
│ └── compare/ # Compare parent command
983-
│ ├── compare.go # Parent command definition
984-
│ └── file-contents/ # File contents comparison subcommand
985-
│ ├── file_contents.go # Command logic
986-
│ ├── file_contents_test.go # Tests
987-
│ ├── comparer.go # Comparison logic
988-
│ ├── differ.go # Diff generation
1169+
│ ├── compare/ # Compare parent command
1170+
│ │ ├── compare.go # Parent command definition
1171+
│ │ └── file-contents/ # File contents comparison subcommand
1172+
│ │ ├── file_contents.go # Command logic
1173+
│ │ ├── file_contents_test.go # Tests
1174+
│ │ ├── comparer.go # Comparison logic
1175+
│ │ ├── differ.go # Diff generation
1176+
│ │ ├── output.go # Output formatting
1177+
│ │ ├── types.go # Type definitions
1178+
│ │ └── version_resolver.go # Version path resolution
1179+
│ └── count/ # Count parent command
1180+
│ ├── count.go # Parent command definition
1181+
│ ├── tested-examples/ # Tested examples counting subcommand
1182+
│ │ ├── tested_examples.go # Command logic
1183+
│ │ ├── tested_examples_test.go # Tests
1184+
│ │ ├── counter.go # Counting logic
1185+
│ │ ├── output.go # Output formatting
1186+
│ │ └── types.go # Type definitions
1187+
│ └── pages/ # Pages counting subcommand
1188+
│ ├── pages.go # Command logic
1189+
│ ├── pages_test.go # Tests
1190+
│ ├── counter.go # Counting logic
9891191
│ ├── output.go # Output formatting
990-
│ ├── types.go # Type definitions
991-
│ └── version_resolver.go # Version path resolution
1192+
│ └── types.go # Type definitions
9921193
├── internal/ # Internal packages
9931194
│ ├── pathresolver/ # Path resolution utilities
9941195
│ │ ├── pathresolver.go # Core path resolution
@@ -1014,12 +1215,14 @@ audit-cli/
10141215
│ ├── includes/ # Included RST files
10151216
│ └── code-examples/ # Code files for literalinclude
10161217
├── expected-output/ # Expected extraction results
1017-
└── compare/ # Compare command test data
1018-
├── product/ # Version structure tests
1019-
│ ├── manual/ # Manual version
1020-
│ ├── upcoming/ # Upcoming version
1021-
│ └── v8.0/ # v8.0 version
1022-
└── *.txt # Direct comparison tests
1218+
├── compare/ # Compare command test data
1219+
│ ├── product/ # Version structure tests
1220+
│ │ ├── manual/ # Manual version
1221+
│ │ ├── upcoming/ # Upcoming version
1222+
│ │ └── v8.0/ # v8.0 version
1223+
│ └── *.txt # Direct comparison tests
1224+
└── count-test-monorepo/ # Count command test data
1225+
└── content/code-examples/tested/ # Tested examples structure
10231226
```
10241227

10251228
### Adding New Commands

audit-cli/commands/count/count.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Package count provides the parent command for counting code examples and documentation pages.
2+
//
3+
// This package serves as the parent command for various counting operations.
4+
// Currently supports:
5+
// - tested-examples: Count tested code examples in the MongoDB documentation monorepo
6+
// - pages: Count documentation pages (.txt files) in the MongoDB documentation monorepo
7+
package count
8+
9+
import (
10+
"github.com/mongodb/code-example-tooling/audit-cli/commands/count/pages"
11+
"github.com/mongodb/code-example-tooling/audit-cli/commands/count/tested-examples"
12+
"github.com/spf13/cobra"
13+
)
14+
15+
// NewCountCommand creates the count parent command.
16+
//
17+
// This command serves as a parent for various counting operations on code examples and documentation pages.
18+
// It doesn't perform any operations itself but provides a namespace for subcommands.
19+
func NewCountCommand() *cobra.Command {
20+
cmd := &cobra.Command{
21+
Use: "count",
22+
Short: "Count code examples and documentation pages",
23+
Long: `Count various types of content in the MongoDB documentation.
24+
25+
Currently supports:
26+
- tested-examples: Count tested code examples in the documentation monorepo
27+
- pages: Count documentation pages (.txt files) in the documentation monorepo`,
28+
}
29+
30+
// Add subcommands
31+
cmd.AddCommand(tested_examples.NewTestedExamplesCommand())
32+
cmd.AddCommand(pages.NewPagesCommand())
33+
34+
return cmd
35+
}
36+

0 commit comments

Comments
 (0)