summaryrefslogtreecommitdiffstats
path: root/build.rs
diff options
context:
space:
mode:
authorClement Tsang <34804052+ClementTsang@users.noreply.github.com>2020-08-31 17:50:21 -0400
committerGitHub <noreply@github.com>2020-08-31 17:50:21 -0400
commit34314112154a42f7c1d4d822f94e478b55dbe9b6 (patch)
tree3a063e7d28093ab01c1e3e1b2da3e7442b7b72c9 /build.rs
parentc6a20a14201c46441f82938adf6f3f4bbd7441a8 (diff)
other: Add autocomplete file generation (#213)
Adds shell completion generation as part of the build, as well as tweaking install scripts/templates/CI to use them.
Diffstat (limited to 'build.rs')
-rw-r--r--build.rs31
1 files changed, 31 insertions, 0 deletions
diff --git a/build.rs b/build.rs
new file mode 100644
index 00000000..472a0a6c
--- /dev/null
+++ b/build.rs
@@ -0,0 +1,31 @@
+use clap::Shell;
+use std::{env, fs, process};
+include!("src/clap.rs");
+
+fn main() {
+ // OUT_DIR is where extra build files are written to for Cargo.
+ let out_dir = match env::var_os("OUT_DIR") {
+ Some(out_dir) => out_dir,
+ None => {
+ eprintln!("The OUT_DIR environment variable was not set! Aborting...");
+ process::exit(1)
+ }
+ };
+ match fs::create_dir_all(&out_dir) {
+ Ok(()) => {}
+ Err(err) => {
+ eprintln!(
+ "Failed to create a directory at OUT_DIR location {:?}, encountered error {:?}. Aborting...",
+ out_dir, err
+ );
+ process::exit(1)
+ }
+ }
+
+ // Generate completions
+ let mut app = build_app();
+ app.gen_completions("btm", Shell::Bash, &out_dir);
+ app.gen_completions("btm", Shell::Zsh, &out_dir);
+ app.gen_completions("btm", Shell::Fish, &out_dir);
+ app.gen_completions("btm", Shell::PowerShell, &out_dir);
+}