KeiSeiKit-1.0/_primitives/_rust/mock-render/src/cli_args.rs
Parfii-bot 0be354a920 KeiSeiKit-public — clean state
Single-commit clean baseline after security scrub of niche-tells,
project codenames, internal jargon, and contributor-email leaks.

Contents:
- 100 Rust crates (_primitives/_rust/)
- 37 agent manifests (_manifests/) + generated specs (_generated/)
- 67 user-invocable skills (skills/)
- 33 hooks (hooks/)
- Composition blocks (_blocks/)
- Documentation (docs/, README.md)
- TS adapter packages (_ts_packages/)
- Assembler (_assembler/)
- Roles (_roles/)
- Templates (_templates/)
- Forgejo CI (.forgejo/)

Author: Denis Parfionovich <info@greendragon.info>

License: see LICENSE.
2026-05-01 12:09:03 +08:00

33 lines
1.1 KiB
Rust

//! Shared CLI-arg helpers for every mock-render subcommand.
//!
//! Extracted from `main.rs` in v0.14.1 to keep that dispatcher ≤40 LOC
//! per Constructor Pattern.
use std::path::PathBuf;
/// Look up a `--name <value>` pair in the arg slice.
pub fn flag<'a>(args: &'a [String], name: &str) -> Option<&'a str> {
args.windows(2)
.find(|w| w[0] == name)
.map(|w| w[1].as_str())
}
/// Parse `WxH` viewport (e.g. `1280x800`).
pub fn parse_viewport(s: &str) -> Option<(u32, u32)> {
let (w, h) = s.split_once('x')?;
Some((w.parse().ok()?, h.parse().ok()?))
}
/// Require `--project` (default `.`) and `--section <existing-file>`.
pub fn require_project_section(args: &[String]) -> Result<(PathBuf, PathBuf), String> {
let project = flag(args, "--project")
.map(PathBuf::from)
.unwrap_or_else(|| PathBuf::from("."));
let section = flag(args, "--section")
.map(PathBuf::from)
.ok_or_else(|| "--section <file> required".to_string())?;
if !section.exists() {
return Err(format!("section file not found: {}", section.display()));
}
Ok((project, section))
}