Print version of the crate

Print version acquired from Cargo when building. If built using rustc
directly, print X.X.X
This commit is contained in:
Jan Likar 2015-11-18 00:51:15 +01:00
parent 1eb38c461e
commit f85ff8d0e5

View file

@ -23,7 +23,6 @@ use rustfmt::config::Config;
use std::env;
use std::fs::{self, File};
use std::io::{self, Read, Write};
use std::process::Command;
use std::path::{Path, PathBuf};
use getopts::{Matches, Options};
@ -177,15 +176,11 @@ fn print_usage(opts: &Options, reason: &str) {
}
fn print_version() {
let cmd = Command::new("git")
.arg("rev-parse")
.arg("--short")
.arg("HEAD")
.output();
match cmd {
Ok(output) => print!("{}", String::from_utf8(output.stdout).unwrap()),
Err(e) => panic!("Unable te get version: {}", e),
}
println!("{}.{}.{}{}",
option_env!("CARGO_PKG_VERSION_MAJOR").unwrap_or("X"),
option_env!("CARGO_PKG_VERSION_MINOR").unwrap_or("X"),
option_env!("CARGO_PKG_VERSION_PATCH").unwrap_or("X"),
option_env!("CARGO_PKG_VERSION_PRE").unwrap_or(""));
}
fn determine_operation(matches: &Matches) -> Operation {