From 66c5766848d075aafb4af382d09a140a3d59bdee Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Fri, 26 Dec 2025 10:26:00 -0800 Subject: [PATCH] feat(cli): add custom output fir for docgen cmd --- komorebic/src/main.rs | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/komorebic/src/main.rs b/komorebic/src/main.rs index 8671ab83..6c4b7d28 100644 --- a/komorebic/src/main.rs +++ b/komorebic/src/main.rs @@ -785,6 +785,13 @@ struct AnimationStyle { animation_type: Option, } +#[derive(Parser)] +struct Docgen { + /// Output directory for generated documentation files + #[clap(short, long)] + output: Option, +} + #[derive(Parser)] #[allow(clippy::struct_excessive_bools)] struct Start { @@ -1015,7 +1022,7 @@ struct Opts { #[derive(Parser)] enum SubCommand { #[clap(hide = true)] - Docgen, + Docgen(Docgen), #[clap(hide = true)] Splash(Splash), /// Gather example configurations for a new-user quickstart @@ -1582,10 +1589,12 @@ fn main() -> eyre::Result<()> { let opts: Opts = Opts::parse(); match opts.subcmd { - SubCommand::Docgen => { + SubCommand::Docgen(args) => { let mut cli = Opts::command(); let subcommands = cli.get_subcommands_mut(); - std::fs::create_dir_all("docs/cli")?; + + let output_dir = args.output.unwrap_or_else(|| PathBuf::from("docs/cli")); + std::fs::create_dir_all(&output_dir)?; let ignore = [ "docgen", @@ -1606,10 +1615,10 @@ fn main() -> eyre::Result<()> { let name = cmd.get_name().to_string(); if !ignore.contains(&name.as_str()) { let help_text = cmd.render_long_help().to_string(); - let outpath = format!("docs/cli/{name}.md"); - let markdown = format!("# {name}\n\n```\n{help_text}\n```"); - std::fs::write(outpath, markdown)?; - println!(" - cli/{name}.md"); + let outpath = output_dir.join(format!("{name}.md")); + let markdown = format!("```\n{help_text}\n```"); + std::fs::write(&outpath, markdown)?; + println!("{}", outpath.display()); } } }