@@ -58,7 +58,8 @@ audit-cli
5858├── search # Search through extracted content or source files
5959│ └── find-string
6060├── analyze # Analyze RST file structures
61- │ └── includes
61+ │ ├── includes
62+ │ └── references
6263└── compare # Compare files across versions
6364 └── file-contents
6465```
@@ -282,6 +283,196 @@ times (e.g., file A includes file C, and file B also includes file C), the file
282283However, the tree view will show it in all locations where it appears, with subsequent occurrences marked as circular
283284includes in verbose mode.
284285
286+ #### ` analyze references `
287+
288+ Find all files that reference a target file through RST directives. This performs reverse dependency analysis, showing which files reference the target file through ` include ` , ` literalinclude ` , or ` io-code-block ` directives.
289+
290+ The command searches all RST files (both ` .rst ` and ` .txt ` extensions) in the source directory tree.
291+
292+ ** Use Cases:**
293+
294+ This command helps writers:
295+ - Understand the impact of changes to a file (what pages will be affected)
296+ - Find all usages of an include file across the documentation
297+ - Track where code examples are referenced
298+ - Identify orphaned files (files with no references)
299+ - Plan refactoring by understanding file dependencies
300+
301+ ** Basic Usage:**
302+
303+ ``` bash
304+ # Find what references an include file
305+ ./audit-cli analyze references path/to/includes/fact.rst
306+
307+ # Find what references a code example
308+ ./audit-cli analyze references path/to/code-examples/example.js
309+
310+ # Get JSON output for automation
311+ ./audit-cli analyze references path/to/file.rst --format json
312+
313+ # Show detailed information with line numbers
314+ ./audit-cli analyze references path/to/file.rst --verbose
315+ ```
316+
317+ ** Flags:**
318+
319+ - ` --format <format> ` - Output format: ` text ` (default) or ` json `
320+ - ` -v, --verbose ` - Show detailed information including line numbers and reference paths
321+ - ` -c, --count-only ` - Only show the count of references (useful for quick checks and scripting)
322+ - ` --paths-only ` - Only show the file paths, one per line (useful for piping to other commands)
323+ - ` -t, --directive-type <type> ` - Filter by directive type: ` include ` , ` literalinclude ` , or ` io-code-block `
324+
325+ ** Understanding the Counts:**
326+
327+ The command shows two metrics:
328+ - ** Total Files** : Number of unique files that reference the target (deduplicated)
329+ - ** Total References** : Total number of directive occurrences (includes duplicates)
330+
331+ When a file includes the target multiple times, it counts as:
332+ - 1 file (in Total Files)
333+ - Multiple references (in Total References)
334+
335+ This helps identify both the impact scope (how many files) and duplicate includes (when references > files).
336+
337+ ** Supported Directive Types:**
338+
339+ The command tracks three types of RST directives:
340+
341+ 1 . ** ` .. include:: ` ** - RST content includes
342+ ``` rst
343+ .. include:: /includes/intro.rst
344+ ```
345+
346+ 2 . ** ` .. literalinclude:: ` ** - Code file references
347+ ``` rst
348+ .. literalinclude:: /code-examples/example.py
349+ :language: python
350+ ```
351+
352+ 3 . ** ` .. io-code-block:: ` ** - Input/output examples with file arguments
353+ ``` rst
354+ .. io-code-block::
355+
356+ .. input:: /code-examples/query.js
357+ :language: javascript
358+
359+ .. output:: /code-examples/result.json
360+ :language: json
361+ ```
362+
363+ ** Note:** Only file-based references are tracked. Inline content (e.g., ` .. input:: ` with ` :language: ` but no file path) is not tracked.
364+
365+ ** Output Formats:**
366+
367+ ** Text** (default):
368+ ```
369+ ============================================================
370+ REFERENCE ANALYSIS
371+ ============================================================
372+ Target File: /path/to/includes/intro.rst
373+ Total Files: 3
374+ Total References: 4
375+ ============================================================
376+
377+ include : 3 files, 4 references
378+
379+ 1. [include] duplicate-include-test.rst (2 references)
380+ 2. [include] include-test.rst
381+ 3. [include] page.rst
382+
383+ ```
384+
385+ ** Text with --verbose:**
386+ ```
387+ ============================================================
388+ REFERENCE ANALYSIS
389+ ============================================================
390+ Target File: /path/to/includes/intro.rst
391+ Total Files: 3
392+ Total References: 4
393+ ============================================================
394+
395+ include : 3 files, 4 references
396+
397+ 1. [include] duplicate-include-test.rst (2 references)
398+ Line 6: /includes/intro.rst
399+ Line 13: /includes/intro.rst
400+ 2. [include] include-test.rst
401+ Line 6: /includes/intro.rst
402+ 3. [include] page.rst
403+ Line 12: /includes/intro.rst
404+
405+ ```
406+
407+ ** JSON** (--format json):
408+ ``` json
409+ {
410+ "target_file" : " /path/to/includes/intro.rst" ,
411+ "source_dir" : " /path/to/source" ,
412+ "total_files" : 3 ,
413+ "total_references" : 4 ,
414+ "referencing_files" : [
415+ {
416+ "FilePath" : " /path/to/duplicate-include-test.rst" ,
417+ "DirectiveType" : " include" ,
418+ "ReferencePath" : " /includes/intro.rst" ,
419+ "LineNumber" : 6
420+ },
421+ {
422+ "FilePath" : " /path/to/duplicate-include-test.rst" ,
423+ "DirectiveType" : " include" ,
424+ "ReferencePath" : " /includes/intro.rst" ,
425+ "LineNumber" : 13
426+ },
427+ {
428+ "FilePath" : " /path/to/include-test.rst" ,
429+ "DirectiveType" : " include" ,
430+ "ReferencePath" : " /includes/intro.rst" ,
431+ "LineNumber" : 6
432+ }
433+ ]
434+ }
435+ ```
436+
437+ ** Examples:**
438+
439+ ``` bash
440+ # Check if an include file is being used
441+ ./audit-cli analyze references ~ /docs/source/includes/fact-atlas.rst
442+
443+ # Find all pages that use a specific code example
444+ ./audit-cli analyze references ~ /docs/source/code-examples/connect.py
445+
446+ # Get machine-readable output for scripting
447+ ./audit-cli analyze references ~ /docs/source/includes/fact.rst --format json | jq ' .total_references'
448+
449+ # See exactly where a file is referenced (with line numbers)
450+ ./audit-cli analyze references ~ /docs/source/includes/intro.rst --verbose
451+
452+ # Quick check: just show the count
453+ ./audit-cli analyze references ~ /docs/source/includes/fact.rst --count-only
454+ # Output: 5
455+
456+ # Get list of files for piping to other commands
457+ ./audit-cli analyze references ~ /docs/source/includes/fact.rst --paths-only
458+ # Output:
459+ # page1.rst
460+ # page2.rst
461+ # page3.rst
462+
463+ # Filter to only show include directives (not literalinclude or io-code-block)
464+ ./audit-cli analyze references ~ /docs/source/includes/fact.rst --directive-type include
465+
466+ # Filter to only show literalinclude references
467+ ./audit-cli analyze references ~ /docs/source/code-examples/example.py --directive-type literalinclude
468+
469+ # Combine filters: count only literalinclude references
470+ ./audit-cli analyze references ~ /docs/source/code-examples/example.py -t literalinclude -c
471+
472+ # Combine filters: list files that use this as an io-code-block
473+ ./audit-cli analyze references ~ /docs/source/code-examples/query.js -t io-code-block --paths-only
474+ ```
475+
285476### Compare Commands
286477
287478#### ` compare file-contents `
@@ -469,9 +660,15 @@ audit-cli/
469660│ │ └── report.go # Report generation
470661│ ├── analyze/ # Analyze parent command
471662│ │ ├── analyze.go # Parent command definition
472- │ │ └── includes/ # Includes analysis subcommand
473- │ │ ├── includes.go # Command logic
474- │ │ ├── analyzer.go # Include tree building
663+ │ │ ├── includes/ # Includes analysis subcommand
664+ │ │ │ ├── includes.go # Command logic
665+ │ │ │ ├── analyzer.go # Include tree building
666+ │ │ │ ├── output.go # Output formatting
667+ │ │ │ └── types.go # Type definitions
668+ │ │ └── references/ # References analysis subcommand
669+ │ │ ├── references.go # Command logic
670+ │ │ ├── references_test.go # Tests
671+ │ │ ├── analyzer.go # Reference finding logic
475672│ │ ├── output.go # Output formatting
476673│ │ └── types.go # Type definitions
477674│ └── compare/ # Compare parent command
@@ -485,6 +682,12 @@ audit-cli/
485682│ ├── types.go # Type definitions
486683│ └── version_resolver.go # Version path resolution
487684├── internal/ # Internal packages
685+ │ ├── pathresolver/ # Path resolution utilities
686+ │ │ ├── pathresolver.go # Core path resolution
687+ │ │ ├── pathresolver_test.go # Tests
688+ │ │ ├── source_finder.go # Source directory detection
689+ │ │ ├── version_resolver.go # Version path resolution
690+ │ │ └── types.go # Type definitions
488691│ └── rst/ # RST parsing utilities
489692│ ├── parser.go # Generic parsing with includes
490693│ ├── include_resolver.go # Include directive resolution
@@ -1075,6 +1278,23 @@ used as the base for resolving relative include paths.
10751278
10761279## Internal Packages
10771280
1281+ ### `internal/pathresolver`
1282+
1283+ Provides centralized path resolution utilities for working with MongoDB documentation structure:
1284+
1285+ - **Source directory detection** - Finds the documentation root by walking up the directory tree
1286+ - **Project info detection** - Identifies product directory, version, and whether a project is versioned
1287+ - **Version path resolution** - Resolves file paths across multiple documentation versions
1288+ - **Relative path resolution** - Resolves paths relative to the source directory
1289+
1290+ **Key Functions:**
1291+ - `FindSourceDirectory(filePath string)` - Finds the source directory for a given file
1292+ - `DetectProjectInfo(filePath string)` - Detects project structure information
1293+ - `ResolveVersionPaths(referenceFile, productDir string, versions []string)` - Resolves paths across versions
1294+ - `ResolveRelativeToSource(sourceDir, relativePath string)` - Resolves relative paths
1295+
1296+ See the code in `internal/pathresolver/` for implementation details.
1297+
10781298### `internal/rst`
10791299
10801300Provides reusable utilities for parsing and processing RST files:
0 commit comments