Skip to content

Commit 986481e

Browse files
author
Stefan Kapferer
committed
Add version to CLI output
1 parent f4995d0 commit 986481e

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

build.gradle

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ application {
3535
startScripts {
3636
applicationName = 'cm'
3737
}
38+
jar {
39+
manifest {
40+
attributes (
41+
'Implementation-Title': 'Context Mapper Command Line Interface (CLI)',
42+
'Implementation-Version': project.version,
43+
'Main-Class': 'org.contextmapper.cli.ContextMapperCLI'
44+
)
45+
}
46+
}
3847

3948
if (!project.hasProperty('signing.secretKeyRingFile')) {
4049
project.ext.'signing.secretKeyRingFile' = "${rootDir}/secret-key.gpg"

src/main/java/org/contextmapper/cli/ContextMapperCLI.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public static void main(String[] args) {
3939
}
4040

4141
protected void run(String[] args) {
42-
System.out.println("Context Mapper CLI");
42+
System.out.println("Context Mapper CLI " + getVersion());
4343

4444
if (args == null || args.length == 0) {
4545
printUsages();
@@ -54,4 +54,9 @@ private void printUsages() {
5454
System.out.println("Usage: cm " + COMPILE_COMMAND + "|" + GENERATE_COMMAND + " [options]");
5555
}
5656

57+
private String getVersion() {
58+
String implVersion = ContextMapperCLI.class.getPackage().getImplementationVersion();
59+
return implVersion != null ? "v" + implVersion : "DEVELOPMENT VERSION";
60+
}
61+
5762
}

src/test/java/org/contextmapper/cli/ContextMapperCLITest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ void main_WhenCalledWithoutCommand_ThenPrintUsage() {
6969
ContextMapperCLI.main(params);
7070

7171
// then
72-
assertThat(outContent.toString()).isEqualTo("Context Mapper CLI" + System.lineSeparator() +
72+
assertThat(outContent.toString()).isEqualTo("Context Mapper CLI DEVELOPMENT VERSION" + System.lineSeparator() +
7373
"Usage: cm compile|generate [options]" + System.lineSeparator());
7474
}
7575

@@ -82,7 +82,7 @@ void run_WhenCalledWithoutCommand_ThenPrintUsage() {
8282
contextMapperCLI.run(params);
8383

8484
// then
85-
assertThat(outContent.toString()).isEqualTo("Context Mapper CLI" + System.lineSeparator() +
85+
assertThat(outContent.toString()).isEqualTo("Context Mapper CLI DEVELOPMENT VERSION" + System.lineSeparator() +
8686
"Usage: cm compile|generate [options]" + System.lineSeparator());
8787
}
8888

0 commit comments

Comments
 (0)