feat(cli): add custom output fir for docgen cmd

This commit is contained in:
LGUG2Z
2025-12-26 10:26:00 -08:00
parent ac56590791
commit 66c5766848

View File

@@ -785,6 +785,13 @@ struct AnimationStyle {
animation_type: Option<komorebi_client::AnimationPrefix>, animation_type: Option<komorebi_client::AnimationPrefix>,
} }
#[derive(Parser)]
struct Docgen {
/// Output directory for generated documentation files
#[clap(short, long)]
output: Option<PathBuf>,
}
#[derive(Parser)] #[derive(Parser)]
#[allow(clippy::struct_excessive_bools)] #[allow(clippy::struct_excessive_bools)]
struct Start { struct Start {
@@ -1015,7 +1022,7 @@ struct Opts {
#[derive(Parser)] #[derive(Parser)]
enum SubCommand { enum SubCommand {
#[clap(hide = true)] #[clap(hide = true)]
Docgen, Docgen(Docgen),
#[clap(hide = true)] #[clap(hide = true)]
Splash(Splash), Splash(Splash),
/// Gather example configurations for a new-user quickstart /// Gather example configurations for a new-user quickstart
@@ -1582,10 +1589,12 @@ fn main() -> eyre::Result<()> {
let opts: Opts = Opts::parse(); let opts: Opts = Opts::parse();
match opts.subcmd { match opts.subcmd {
SubCommand::Docgen => { SubCommand::Docgen(args) => {
let mut cli = Opts::command(); let mut cli = Opts::command();
let subcommands = cli.get_subcommands_mut(); 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 = [ let ignore = [
"docgen", "docgen",
@@ -1606,10 +1615,10 @@ fn main() -> eyre::Result<()> {
let name = cmd.get_name().to_string(); let name = cmd.get_name().to_string();
if !ignore.contains(&name.as_str()) { if !ignore.contains(&name.as_str()) {
let help_text = cmd.render_long_help().to_string(); let help_text = cmd.render_long_help().to_string();
let outpath = format!("docs/cli/{name}.md"); let outpath = output_dir.join(format!("{name}.md"));
let markdown = format!("# {name}\n\n```\n{help_text}\n```"); let markdown = format!("```\n{help_text}\n```");
std::fs::write(outpath, markdown)?; std::fs::write(&outpath, markdown)?;
println!(" - cli/{name}.md"); println!("{}", outpath.display());
} }
} }
} }