File: build.rs

package info (click to toggle)
rust-sequoia-sqv 1.3.0-3
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 592 kB
  • sloc: makefile: 58
file content (42 lines) | stat: -rw-r--r-- 1,039 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
use anyhow::Result;

use clap::ValueEnum;

use clap_complete::Shell;

use sequoia_man::asset_out_dir;

mod cli {
    include!("src/cli/mod.rs");
}

fn main() {
    println!("cargo:rerun-if-changed=build.rs");

    let mut sqv = cli::build();
    generate_shell_completions(&mut sqv).unwrap();
    generate_man_pages(&mut sqv).unwrap();
}

/// Generates shell completions.
fn generate_shell_completions(sqv: &mut clap::Command) -> Result<()> {
    let path = asset_out_dir("shell-completions")?;

    for shell in Shell::value_variants() {
        clap_complete::generate_to(*shell, sqv, "sqv", &path)?;
    };

    println!("cargo:warning=shell completions written to {}", path.display());
    Ok(())
}

/// Generates man pages.
fn generate_man_pages(sqv: &mut clap::Command) -> Result<()> {
    let version = env!("CARGO_PKG_VERSION");
    let builder = sequoia_man::man::Builder::new(sqv, version, None);

    let man_pages = asset_out_dir("man-pages")?;

    sequoia_man::generate_man_pages(&man_pages, &builder).unwrap();
    Ok(())
}