1 /// This build script checks for env vars to build ouch with shell completions and man pages.
3 /// # How to generate shell completions and man pages:
5 /// Set `OUCH_ARTIFACTS_FOLDER` to the name of the destination folder:
8 /// OUCH_ARTIFACTS_FOLDER=my-folder cargo build
11 /// All completion files will be generated inside of the folder "my-folder".
13 /// If the folder does not exist, it will be created.
15 /// We recommend you naming this folder "artifacts" for the sake of consistency.
18 /// OUCH_ARTIFACTS_FOLDER=artifacts cargo build
22 fs::{create_dir_all, File},
26 use clap::{CommandFactory, ValueEnum};
27 use clap_complete::{generate_to, Shell};
30 include!("src/opts.rs");
33 println!("cargo:rerun-if-env-changed=OUCH_ARTIFACTS_FOLDER");
35 if let Some(dir) = env::var_os("OUCH_ARTIFACTS_FOLDER") {
36 let out = &Path::new(&dir);
37 create_dir_all(out).unwrap();
38 let cmd = &mut Opts::command();
41 .render(&mut File::create(out.join("ouch.1")).unwrap())
44 for subcmd in cmd.get_subcommands() {
45 let name = format!("ouch-{}", subcmd.get_name());
46 Man::new(subcmd.clone().name(&name))
47 .render(&mut File::create(out.join(format!("{name}.1"))).unwrap())
51 for shell in Shell::value_variants() {
52 generate_to(*shell, cmd, "ouch", out).unwrap();