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:
parent
1eb38c461e
commit
f85ff8d0e5
1 changed files with 5 additions and 10 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue