From f85ff8d0e5e0149807c3f83b3554bf70ddf70831 Mon Sep 17 00:00:00 2001 From: Jan Likar Date: Wed, 18 Nov 2015 00:51:15 +0100 Subject: [PATCH] Print version of the crate Print version acquired from Cargo when building. If built using rustc directly, print X.X.X --- src/bin/rustfmt.rs | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/bin/rustfmt.rs b/src/bin/rustfmt.rs index 4e8be851c16d..126f893130f5 100644 --- a/src/bin/rustfmt.rs +++ b/src/bin/rustfmt.rs @@ -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 {