File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ type Result<T> = result::Result<T, Error>;
22
22
23
23
struct Info {
24
24
project_name : String ,
25
+ version : String ,
25
26
language : Language ,
26
27
authors : Vec < String > ,
27
28
repo : String ,
@@ -43,6 +44,13 @@ impl fmt::Display for Info {
43
44
"Project: " . color( color) . bold( ) ,
44
45
self . project_name
45
46
) ?;
47
+
48
+ writeln ! (
49
+ buffer,
50
+ "{}{}" ,
51
+ "Version: " . color( color) . bold( ) ,
52
+ self . version
53
+ ) ?;
46
54
writeln ! (
47
55
buffer,
48
56
"{}{}" ,
@@ -217,9 +225,11 @@ fn main() -> Result<()> {
217
225
218
226
let authors = get_authors ( 3 ) ;
219
227
let config = get_configuration ( ) ?;
228
+ let version = get_version ( ) ?;
220
229
221
230
let info = Info {
222
231
project_name : config. repository_name ,
232
+ version,
223
233
language,
224
234
authors,
225
235
repo : config. repository_url ,
@@ -268,6 +278,24 @@ fn project_license() -> Result<String> {
268
278
}
269
279
}
270
280
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
+
271
299
fn is_git_installed ( ) -> bool {
272
300
Command :: new ( "git" )
273
301
. arg ( "--version" )
You can’t perform that action at this time.
0 commit comments