mirror of
https://github.com/asciinema/asciinema.git
synced 2025-12-16 11:48:13 +01:00
Generate man page and shell completions files with cargo build in $ASCIINEMA_GEN_DIR
Closes #627 Closes #628
This commit is contained in:
27
build.rs
27
build.rs
@@ -3,24 +3,35 @@ use clap::ValueEnum;
|
|||||||
use clap_complete::{generate_to, Shell};
|
use clap_complete::{generate_to, Shell};
|
||||||
use clap_mangen::Man;
|
use clap_mangen::Man;
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::fs::File;
|
use std::fs::{create_dir_all, File};
|
||||||
use std::io;
|
use std::path::Path;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
mod cli {
|
mod cli {
|
||||||
include!("src/cli.rs");
|
include!("src/cli.rs");
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() -> std::io::Result<()> {
|
const ENV_KEY: &str = "ASCIINEMA_GEN_DIR";
|
||||||
let out_dir = PathBuf::from(env::var_os("OUT_DIR").ok_or(io::ErrorKind::NotFound)?);
|
|
||||||
let mut cmd = cli::Cli::command();
|
|
||||||
|
|
||||||
let man = Man::new(cmd.clone());
|
fn main() -> std::io::Result<()> {
|
||||||
man.render(&mut File::create(out_dir.join("asciinema.1"))?)?;
|
if let Some(dir) = env::var_os(ENV_KEY).or(env::var_os("OUT_DIR")) {
|
||||||
|
let mut cmd = cli::Cli::command();
|
||||||
|
let base_dir = PathBuf::from(dir);
|
||||||
|
|
||||||
|
let man_dir = Path::join(&base_dir, "man");
|
||||||
|
create_dir_all(&man_dir)?;
|
||||||
|
let man_path = Path::join(&man_dir, "asciinema.1");
|
||||||
|
Man::new(cmd.clone()).render(&mut File::create(man_path)?)?;
|
||||||
|
|
||||||
|
let completion_dir = Path::join(&base_dir, "completion");
|
||||||
|
create_dir_all(&completion_dir)?;
|
||||||
|
|
||||||
for shell in Shell::value_variants() {
|
for shell in Shell::value_variants() {
|
||||||
generate_to(*shell, &mut cmd, "asciinema", &out_dir).unwrap();
|
generate_to(*shell, &mut cmd, "asciinema", &completion_dir)?;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
println!("cargo:rerun-if-env-changed={ENV_KEY}");
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user