about summary refs log tree commit diff stats
path: root/pkgs/by-name/ts/tskm/build.rs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--pkgs/by-name/ts/tskm/build.rs49
1 files changed, 49 insertions, 0 deletions
diff --git a/pkgs/by-name/ts/tskm/build.rs b/pkgs/by-name/ts/tskm/build.rs
new file mode 100644
index 00000000..8dfb213b
--- /dev/null
+++ b/pkgs/by-name/ts/tskm/build.rs
@@ -0,0 +1,49 @@
+use anyhow::{Context, Result};
+use clap::{CommandFactory, ValueEnum};
+use clap_complete::generate_to;
+use clap_complete::Shell;
+
+use std::env;
+use std::fs;
+use std::path::PathBuf;
+
+use crate::cli::CliArgs;
+
+pub mod task {
+    include!("src/task/mod.rs");
+}
+
+pub mod interface {
+    pub mod input {
+        include!("src/interface/input/mod.rs");
+    }
+    pub mod project {
+        include!("src/interface/project/mod.rs");
+    }
+}
+
+pub mod cli {
+    include!("src/cli.rs");
+}
+
+fn main() -> Result<()> {
+    let outdir = match env::var_os("SHELL_COMPLETION_DIR") {
+        None => return Ok(()),
+        Some(outdir) => outdir,
+    };
+
+    if !PathBuf::from(&outdir).exists() {
+        fs::create_dir_all(&outdir)?;
+    }
+
+    let mut cmd = CliArgs::command();
+
+    for &shell in Shell::value_variants() {
+        let path = generate_to(shell, &mut cmd, "tskm", &outdir).with_context(|| {
+            format!("Failed to output shell completion for {shell} to {outdir:?}")
+        })?;
+        println!("cargo:warning=completion file for {shell} is generated at: {path:?}");
+    }
+
+    Ok(())
+}