Skip to content

Commit

Permalink
Add support for manpages
Browse files Browse the repository at this point in the history
  • Loading branch information
dani-garcia committed Aug 21, 2023
1 parent f38a84e commit a4aa3b5
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
17 changes: 17 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/bws/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ chrono = { version = "0.4.26", features = [
], default-features = false }
clap = { version = "4.3.0", features = ["derive", "env", "string"] }
clap_complete = "4.3.2"
clap_mangen = "0.2.12"
color-eyre = "0.6"
comfy-table = "^7.0.1"
directories = "5.0.1"
Expand Down
22 changes: 21 additions & 1 deletion crates/bws/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ enum Commands {

#[command(long_about = "Generate shell completion files")]
Completions { shell: Option<Shell> },
#[command(long_about = "Generate manpages at the provided path")]
ManPage { path: PathBuf },

#[command(long_about = "Commands available on Projects")]
Project {
Expand Down Expand Up @@ -262,6 +264,24 @@ async fn process_commands() -> Result<()> {
return Ok(());
}

if let Commands::ManPage { path } = command {
std::fs::create_dir_all(&path)?;
let cmd = Cli::command();

let man = clap_mangen::Man::new(cmd.clone());
let mut buffer: Vec<u8> = Default::default();
man.render(&mut buffer)?;
std::fs::write(path.join("bws.1"), buffer)?;

for sc in cmd.get_subcommands() {
let name = format!("bws-{}", sc.get_name());
let mut buffer: Vec<u8> = Vec::new();
clap_mangen::Man::new(sc.clone().name(&name)).render(&mut buffer)?;
std::fs::write(path.join(format!("{}{}", &name, ".1")), buffer)?;
}
return Ok(());
}

// Modify profile commands
if let Commands::Config {
name,
Expand Down Expand Up @@ -594,7 +614,7 @@ async fn process_commands() -> Result<()> {
}
}

Commands::Config { .. } | Commands::Completions { .. } => {
Commands::Config { .. } | Commands::Completions { .. } | Commands::ManPage { .. } => {
unreachable!()
}
}
Expand Down

0 comments on commit a4aa3b5

Please sign in to comment.