use crate::cli::Cli;
use clap::CommandFactory;
#[derive(Debug, clap::Args)]
#[clap(hide = true, verbatim_doc_comment)]
pub struct Usage {}
fn generate_to_string() -> String {
let mut cmd = Cli::command();
let mut spec = clap_usage::spec(&mut cmd, "communique");
crate::command_effects::apply(&mut spec);
format!(
"// @generated by `communique usage` from clap metadata\nmin_usage_version \"4.0\"\n{spec}"
)
}
impl Usage {
pub fn run(&self) -> miette::Result<()> {
println!("{}", generate_to_string());
Ok(())
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn run_succeeds() {
assert!(Usage {}.run().is_ok());
}
#[test]
fn test_usage_kdl_in_sync() {
let generated = generate_to_string();
let on_disk = std::fs::read_to_string(
std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("communique.usage.kdl"),
)
.expect("communique.usage.kdl should exist");
assert_eq!(
generated.trim(),
on_disk.trim(),
"communique.usage.kdl is out of sync — run `cargo run -- usage > communique.usage.kdl` to update"
);
}
}