diff options
| author | Weicao-CatilGrass <1992414357@qq.com> | 2026-06-12 19:44:57 +0800 |
|---|---|---|
| committer | Weicao-CatilGrass <1992414357@qq.com> | 2026-06-12 19:44:57 +0800 |
| commit | c51c592a9a977dfdcaa754214a4e1c2e7964d6e8 (patch) | |
| tree | f89fd2ce29bb49e24441acfdfdc7cfe8b8ffc874 /dev_tools/src/bin/test-all-markdown-code.rs | |
| parent | d64afc27578ca83aeb7f78b98e2469b995c07171 (diff) | |
Add optional single file argument to test runner
Diffstat (limited to 'dev_tools/src/bin/test-all-markdown-code.rs')
| -rw-r--r-- | dev_tools/src/bin/test-all-markdown-code.rs | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/dev_tools/src/bin/test-all-markdown-code.rs b/dev_tools/src/bin/test-all-markdown-code.rs index 500e66a..e43053e 100644 --- a/dev_tools/src/bin/test-all-markdown-code.rs +++ b/dev_tools/src/bin/test-all-markdown-code.rs @@ -1,4 +1,5 @@ use std::collections::HashMap; +use std::env; use std::path::{Path, PathBuf}; use colored::Colorize; @@ -44,6 +45,22 @@ fn main() { }) }; + // Parse optional path argument from env args + let single_file: Option<PathBuf> = { + let args: Vec<String> = env::args().collect(); + if args.len() > 1 { + let p = PathBuf::from(&args[1]); + if p.exists() { + Some(p) + } else { + eprintln_cargo_style!("error: specified file '{}' does not exist", args[1]); + std::process::exit(1); + } + } else { + None + } + }; + // Collect all markdown files from config let mut files: Vec<(String, PathBuf)> = Vec::new(); @@ -74,6 +91,25 @@ fn main() { } } + // If a single file was specified, filter the list to only that file + if let Some(ref target) = single_file { + // Canonicalize to compare paths reliably + let target_canon = std::fs::canonicalize(target).unwrap_or_else(|_| target.clone()); + files.retain(|(_, path)| { + std::fs::canonicalize(path) + .map(|p| p == target_canon) + .unwrap_or(false) + }); + if files.is_empty() { + eprintln_cargo_style!( + "error: specified file '{}' is not among the configured documentation files", + target.display() + ); + std::process::exit(1); + } + println_cargo_style!("Source: testing only file '{}'", target.display()); + } + if files.is_empty() { eprintln_cargo_style!("No markdown files found to verify"); std::process::exit(1); |
