12
12
*/
13
13
package io .openmanufacturing .sds ;
14
14
15
+ import java .io .IOException ;
16
+ import java .io .InputStream ;
17
+ import java .util .Properties ;
18
+
15
19
import org .fusesource .jansi .AnsiConsole ;
16
20
17
21
import io .openmanufacturing .sds .aspect .AspectCommand ;
@@ -34,6 +38,9 @@ public class BammCli extends AbstractCommand {
34
38
35
39
private final CommandLine commandLine = new CommandLine ( this );
36
40
41
+ @ CommandLine .Option ( names = { "--version" }, description = "Show current version" )
42
+ private boolean version ;
43
+
37
44
public void run ( final String ... argv ) throws Exception {
38
45
main ( argv );
39
46
}
@@ -55,8 +62,29 @@ protected String format( final String string ) {
55
62
return commandLine .getColorScheme ().ansi ().string ( string );
56
63
}
57
64
65
+ private Properties loadProperties ( final String filename ) {
66
+ final Properties properties = new Properties ();
67
+ final InputStream propertiesResource = BammCli .class .getClassLoader ().getResourceAsStream ( filename );
68
+ try {
69
+ properties .load ( propertiesResource );
70
+ } catch ( final IOException exception ) {
71
+ throw new RuntimeException ( "Failed to load Properties: " + filename );
72
+ }
73
+ return properties ;
74
+ }
75
+
58
76
@ Override
59
77
public void run () {
78
+ if ( version ) {
79
+ final Properties applicationProperties = loadProperties ( "application.properties" );
80
+ final Properties gitProperties = loadProperties ( "git.properties" );
81
+ System .out .printf ( "bamm-cli - %s%nVersion: %s%nBuild date: %s%nGit commit: %s%n" ,
82
+ applicationProperties .get ( "application.name" ),
83
+ applicationProperties .get ( "version" ),
84
+ applicationProperties .get ( "build.date" ),
85
+ gitProperties .get ( "git.commit.id" ) );
86
+ System .exit ( 0 );
87
+ }
60
88
System .out .println ( commandLine .getHelp ().fullSynopsis () );
61
89
System .out .println ( format ( "Run @|bold " + commandLine .getCommandName () + " help|@ for help." ) );
62
90
}
0 commit comments