Skip to content

Commit 3208ff1

Browse files
committed
Add --version switch to bamm-cli
1 parent 92d5790 commit 3208ff1

File tree

1 file changed

+28
-0
lines changed
  • tools/bamm-cli/src/main/java/io/openmanufacturing/sds

1 file changed

+28
-0
lines changed

tools/bamm-cli/src/main/java/io/openmanufacturing/sds/BammCli.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
*/
1313
package io.openmanufacturing.sds;
1414

15+
import java.io.IOException;
16+
import java.io.InputStream;
17+
import java.util.Properties;
18+
1519
import org.fusesource.jansi.AnsiConsole;
1620

1721
import io.openmanufacturing.sds.aspect.AspectCommand;
@@ -34,6 +38,9 @@ public class BammCli extends AbstractCommand {
3438

3539
private final CommandLine commandLine = new CommandLine( this );
3640

41+
@CommandLine.Option( names = { "--version" }, description = "Show current version" )
42+
private boolean version;
43+
3744
public void run( final String... argv ) throws Exception {
3845
main( argv );
3946
}
@@ -55,8 +62,29 @@ protected String format( final String string ) {
5562
return commandLine.getColorScheme().ansi().string( string );
5663
}
5764

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+
5876
@Override
5977
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+
}
6088
System.out.println( commandLine.getHelp().fullSynopsis() );
6189
System.out.println( format( "Run @|bold " + commandLine.getCommandName() + " help|@ for help." ) );
6290
}

0 commit comments

Comments
 (0)