mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-03-22 09:29:24 +01:00
feat(cli): add custom output fir for docgen cmd
This commit is contained in:
@@ -785,6 +785,13 @@ struct AnimationStyle {
|
||||
animation_type: Option<komorebi_client::AnimationPrefix>,
|
||||
}
|
||||
|
||||
#[derive(Parser)]
|
||||
struct Docgen {
|
||||
/// Output directory for generated documentation files
|
||||
#[clap(short, long)]
|
||||
output: Option<PathBuf>,
|
||||
}
|
||||
|
||||
#[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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user