Skip to content

Commit 6599801

Browse files
committed
detect version #24
1 parent 7f4b71c commit 6599801

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/main.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ type Result<T> = result::Result<T, Error>;
2222

2323
struct Info {
2424
project_name: String,
25+
version: String,
2526
language: Language,
2627
authors: Vec<String>,
2728
repo: String,
@@ -43,6 +44,13 @@ impl fmt::Display for Info {
4344
"Project: ".color(color).bold(),
4445
self.project_name
4546
)?;
47+
48+
writeln!(
49+
buffer,
50+
"{}{}",
51+
"Version: ".color(color).bold(),
52+
self.version
53+
)?;
4654
writeln!(
4755
buffer,
4856
"{}{}",
@@ -217,9 +225,11 @@ fn main() -> Result<()> {
217225

218226
let authors = get_authors(3);
219227
let config = get_configuration()?;
228+
let version = get_version()?;
220229

221230
let info = Info {
222231
project_name: config.repository_name,
232+
version,
223233
language,
224234
authors,
225235
repo: config.repository_url,
@@ -268,6 +278,24 @@ fn project_license() -> Result<String> {
268278
}
269279
}
270280

281+
fn get_version() -> Result<String> {
282+
let output = Command::new("git")
283+
.arg("describe")
284+
.arg("--abbrev=0")
285+
.arg("--tags")
286+
.output()
287+
.expect("Failed to execute git.");
288+
289+
let output = String::from_utf8_lossy(&output.stdout);
290+
291+
if output == "" {
292+
Ok("??".into())
293+
} else {
294+
Ok(output.to_string().replace('\n', ""))
295+
}
296+
}
297+
298+
271299
fn is_git_installed() -> bool {
272300
Command::new("git")
273301
.arg("--version")

0 commit comments

Comments
 (0)