Skip to content

Commit

Permalink
feat(cli): Generate man page
Browse files Browse the repository at this point in the history
  • Loading branch information
alerque committed Sep 22, 2023
1 parent e221428 commit 90b604a
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
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.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ unic-langid = "0.9"
version = "4.3"
features = [ "derive", "wrap_help" ]

[build-dependencies.clap_mangen]
version = "0.2"

[dependencies.git2]
version = "0.17"
default-features = false
Expand Down
21 changes: 21 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use clap::Command;
use clap_complete::generator::generate_to;
use clap_complete::shells::{Bash, Elvish, Fish, PowerShell, Zsh};
use clap_mangen::Man;
use std::{collections, env, fs};
use vergen::EmitBuilder;

Expand All @@ -16,9 +17,29 @@ fn main() {
};
builder.emit().expect("Unable to generate the cargo keys!");
pass_on_configure_details();
generate_manpage();
generate_shell_completions();
}

/// Generate man page
fn generate_manpage() {
let out_dir = match env::var_os("OUT_DIR") {
None => return,
Some(out_dir) => out_dir,
};
let manpage_dir = path::Path::new(&out_dir);
fs::create_dir_all(manpage_dir).expect("Unable to create directory for generated manpages");
let bin_name: &str = "casile";
let cli = Command::new("casile");
let cli = Cli::augment_args(cli);
let man = Man::new(cli);
let mut buffer: Vec<u8> = Default::default();
man.render(&mut buffer)
.expect("Unable to render man page to UTF-8 string");
fs::write(manpage_dir.join(format!("{bin_name}.1")), buffer)
.expect("Unable to write manepage to file");
}

/// Generate shell completion files from CLI interface
fn generate_shell_completions() {
let out_dir = match env::var_os("OUT_DIR") {
Expand Down

0 comments on commit 90b604a

Please sign in to comment.