use std::env;
use clap::CommandFactory;
use clap_complete::Shell;
use anyhow::Result;
use sequoia_man::asset_out_dir;
pub mod cli {
include!("src/cli/mod.rs");
}
pub mod openpgp {
#[derive(Clone, Debug)]
pub struct KeyHandle {
}
impl From<&str> for KeyHandle {
fn from(_: &str) -> KeyHandle {
KeyHandle {}
}
}
}
fn main() {
let mut cli = cli::build(false);
git_version();
completions();
generate_man_pages(&mut cli).expect("can generate man pages");
}
fn git_version() {
let _ = vergen::EmitBuilder::builder()
.git_describe( true, false, None)
.fail_on_error()
.emit();
}
fn completions() {
let outdir = match std::env::var_os("CARGO_TARGET_DIR") {
None => {
println!("cargo:warning=Not generating completion files, \
environment variable CARGO_TARGET_DIR not set");
return;
}
Some(outdir) => outdir,
};
std::fs::create_dir_all(&outdir).unwrap();
let mut cli = cli::Cli::command();
for shell in &[Shell::Bash, Shell::Fish, Shell::Zsh,
Shell::PowerShell, Shell::Elvish] {
let path = clap_complete::generate_to(
*shell, &mut cli, "sq-git", &outdir).unwrap();
println!("cargo:warning=generated completion file {:?}", path);
};
}
fn generate_man_pages(cli: &mut clap::Command) -> Result<()> {
let version = env!("CARGO_PKG_VERSION");
let mut builder = sequoia_man::man::Builder::new(cli, version, None);
builder.see_also(
&[ "For the full documentation see <https://sequoia-pgp.gitlab.io/sequoia-git>." ]);
let man_pages = asset_out_dir("man-pages")?;
sequoia_man::generate_man_pages(&man_pages, &builder).unwrap();
Ok(())
}