2021-04-20 19:48:12 +00:00
|
|
|
use std::env;
|
2020-10-18 09:22:13 +00:00
|
|
|
use std::process::Command;
|
|
|
|
|
2021-04-20 19:48:12 +00:00
|
|
|
fn git_version() -> Option<String> {
|
|
|
|
let mut git = Command::new("git");
|
|
|
|
git.args(&["describe", "--tags", "--broken"]);
|
|
|
|
|
2021-05-02 21:16:37 +00:00
|
|
|
let output = git.output().ok()?;
|
2021-06-10 03:15:59 +00:00
|
|
|
if !output.status.success() || output.stdout.is_empty() || !output.stderr.is_empty() {
|
|
|
|
return None;
|
|
|
|
}
|
2021-05-02 21:16:37 +00:00
|
|
|
String::from_utf8(output.stdout).ok()
|
2021-04-20 19:48:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn crate_version() -> String {
|
|
|
|
// unwrap is safe here, since Cargo will always supply this variable.
|
|
|
|
format!("v{}", env::var("CARGO_PKG_VERSION").unwrap())
|
|
|
|
}
|
|
|
|
|
2021-05-03 21:12:43 +00:00
|
|
|
fn generate_completions() {
|
2021-05-07 07:34:44 +00:00
|
|
|
#[path = "src/app/_app.rs"]
|
|
|
|
mod app;
|
2021-05-03 21:12:43 +00:00
|
|
|
|
|
|
|
use app::App;
|
|
|
|
use clap::IntoApp;
|
|
|
|
use clap_generate::generate_to;
|
|
|
|
use clap_generate::generators::{Bash, Elvish, Fish, PowerShell, Zsh};
|
|
|
|
|
|
|
|
let app = &mut App::into_app();
|
|
|
|
let bin_name = &env::var("CARGO_PKG_NAME").unwrap();
|
|
|
|
let out_dir = "contrib/completions";
|
|
|
|
|
|
|
|
generate_to::<Bash, _, _>(app, bin_name, out_dir);
|
|
|
|
generate_to::<Elvish, _, _>(app, bin_name, out_dir);
|
|
|
|
generate_to::<Fish, _, _>(app, bin_name, out_dir);
|
|
|
|
generate_to::<PowerShell, _, _>(app, bin_name, out_dir);
|
|
|
|
generate_to::<Zsh, _, _>(app, bin_name, out_dir);
|
|
|
|
}
|
|
|
|
|
2021-04-20 19:48:12 +00:00
|
|
|
fn main() {
|
2021-06-10 03:15:59 +00:00
|
|
|
// Packaged releases of zoxide almost always use the source tarball
|
|
|
|
// provided by GitHub, which does not include the `.git` folder. Since this
|
|
|
|
// feature is only useful for development, we can silently fall back to
|
|
|
|
// using the crate version.
|
2021-04-20 19:48:12 +00:00
|
|
|
let version = git_version().unwrap_or_else(crate_version);
|
|
|
|
println!("cargo:rustc-env=ZOXIDE_VERSION={}", version);
|
2021-05-08 03:05:34 +00:00
|
|
|
|
|
|
|
// Since we are generating completions in the package directory, we need to
|
|
|
|
// set this so that Cargo doesn't rebuild every time.
|
|
|
|
println!("cargo:rerun-if-changed=src");
|
|
|
|
println!("cargo:rerun-if-changed=templates");
|
|
|
|
println!("cargo:rerun-if-changed=tests");
|
|
|
|
|
2021-05-03 21:12:43 +00:00
|
|
|
generate_completions();
|
2020-03-31 21:54:45 +00:00
|
|
|
}
|