Skip to content

Commit

Permalink
detect version #24
Browse files Browse the repository at this point in the history
  • Loading branch information
o2sh committed Jan 13, 2019
1 parent 7f4b71c commit 6599801
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type Result<T> = result::Result<T, Error>;

struct Info {
project_name: String,
version: String,
language: Language,
authors: Vec<String>,
repo: String,
Expand All @@ -43,6 +44,13 @@ impl fmt::Display for Info {
"Project: ".color(color).bold(),
self.project_name
)?;

writeln!(
buffer,
"{}{}",
"Version: ".color(color).bold(),
self.version
)?;
writeln!(
buffer,
"{}{}",
Expand Down Expand Up @@ -217,9 +225,11 @@ fn main() -> Result<()> {

let authors = get_authors(3);
let config = get_configuration()?;
let version = get_version()?;

let info = Info {
project_name: config.repository_name,
version,
language,
authors,
repo: config.repository_url,
Expand Down Expand Up @@ -268,6 +278,24 @@ fn project_license() -> Result<String> {
}
}

fn get_version() -> Result<String> {
let output = Command::new("git")
.arg("describe")
.arg("--abbrev=0")
.arg("--tags")
.output()
.expect("Failed to execute git.");

let output = String::from_utf8_lossy(&output.stdout);

if output == "" {
Ok("??".into())
} else {
Ok(output.to_string().replace('\n', ""))
}
}


fn is_git_installed() -> bool {
Command::new("git")
.arg("--version")
Expand Down

0 comments on commit 6599801

Please sign in to comment.