Skip to content

Commit

Permalink
Print version of the crate
Browse files Browse the repository at this point in the history
Print version acquired from Cargo when building. If built using rustc
directly, print X.X.X
  • Loading branch information
JanLikar committed Nov 17, 2015
1 parent 1eb38c4 commit f85ff8d
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions src/bin/rustfmt.rs
Expand Up @@ -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};
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit f85ff8d

Please sign in to comment.