explict version informations

This commit is contained in:
csmoe 2018-02-19 17:17:27 +08:00
parent 383e7e9955
commit ef05a2d2f1
2 changed files with 16 additions and 5 deletions

View File

@ -27,11 +27,19 @@ fn main() {
// (git not installed or if this is not a git repository) just return an empty string.
fn commit_info() -> String {
match (commit_hash(), commit_date()) {
(Some(hash), Some(date)) => format!(" ({} {})", hash.trim_right(), date),
(Some(hash), Some(date)) => format!("{} ({} {})", channel(), hash.trim_right(), date),
_ => String::new(),
}
}
fn channel() -> String {
if let Ok(channel) = env::var("CFG_RELEASE_CHANNEL") {
channel
} else {
"nightly".to_owned()
}
}
fn commit_hash() -> Option<String> {
Command::new("git")
.args(&["rev-parse", "--short", "HEAD"])

View File

@ -387,10 +387,13 @@ fn print_usage_to_stdout(opts: &Options, reason: &str) {
fn print_version() {
println!(
"{}-nightly{}",
option_env!("CARGO_PKG_VERSION").unwrap_or("unknown"),
include_str!(concat!(env!("OUT_DIR"), "/commit-info.txt"))
)
"rustfmt {}",
concat!(
env!("CARGO_PKG_VERSION"),
"-",
include_str!(concat!(env!("OUT_DIR"), "/commit-info.txt"))
)
);
}
fn determine_operation(matches: &Matches) -> FmtResult<Operation> {