diff options
author | Jesse Luehrs <doy@tozt.net> | 2018-03-04 17:22:29 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2018-03-04 17:33:21 -0500 |
commit | baa60789a163090737cf5206d0c51f8e93793eac (patch) | |
tree | 2230c8822f37043b9b02e5cc0ab7697b4adfb739 | |
parent | 4463924127cff2be36f2b772893e3d793f11ed0b (diff) | |
download | fancy-prompt-baa60789a163090737cf5206d0c51f8e93793eac.tar.gz fancy-prompt-baa60789a163090737cf5206d0c51f8e93793eac.zip |
add version and author data to command line options0.1.0
-rw-r--r-- | build.rs | 29 | ||||
-rw-r--r-- | src/main.rs | 5 |
2 files changed, 33 insertions, 1 deletions
diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..ee9d9e3 --- /dev/null +++ b/build.rs @@ -0,0 +1,29 @@ +fn main() { + println!("cargo:rustc-env=FANCY_PROMPT_BUILD_GIT_REV={}", git_describe()) +} + +fn git_describe() -> String { + let output = std::process::Command::new("git") + .args(&["describe", "--tags"]) + .output(); + output.and_then(|output| { + if output.status.success() { + Ok( + String::from_utf8_lossy(&output.stdout) + .trim() + .to_string() + ) + } + else { + Err( + std::io::Error::new( + std::io::ErrorKind::Other, + "failed to run git" + ) + ) + } + }).unwrap_or_else(|_err| { + // String::from(format!("{}", _err)) + String::from("???") + }) +} diff --git a/src/main.rs b/src/main.rs index 2f9063e..3e5f849 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,5 @@ extern crate chrono; +#[macro_use] extern crate clap; extern crate git2; extern crate hostname; @@ -22,7 +23,9 @@ fn collect_data() -> prompt::PromptData { let matches = clap::App::new("fancy-prompt") .about("Prints a fancy prompt") - // XXX author, version (extract from cargo) + .author(crate_authors!()) + .version(crate_version!()) + .long_version(option_env!("FANCY_PROMPT_BUILD_GIT_REV").unwrap()) .arg(clap::Arg::with_name("prompt-escape") .long("prompt-escape") .value_name("SHELL") |