Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: David Greven <fixed-term.David.Greven@de.bosch.com> Signed-off-by: Sebastian Becker <Sebastian.Becker@de.bosch.com>
- Loading branch information
1 parent
340e817
commit d10625a
Showing
3 changed files
with
84 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package io.carbynestack.cli; | ||
|
||
import picocli.CommandLine; | ||
import picocli.CommandLine.IVersionProvider; | ||
|
||
import java.util.Locale; | ||
|
||
public class Version implements IVersionProvider { | ||
/** | ||
* Returns the version command output as an array of lines. | ||
* | ||
* @return An array of the individual version information lines. | ||
*/ | ||
@Override | ||
public String[] getVersion() { | ||
return String.format(""" | ||
@|bold Command Line Interface to interact with Carbyne Stack Virtual Clouds|@ | ||
Carbyne Stack CLI: %s | ||
@|bold Dependencies:|@ | ||
Picocli: %s | ||
Amphora: 0.1-SNAPSHOT-1261403362-2-41864d | ||
Castor: 0.1-SNAPSHOT-1261403451-2-78f5f5b | ||
Ephemeral: 0.1-SNAPSHOT-1261324039-3-d2504ed | ||
@|bold Runtime & Environment:|@ | ||
JVM: ${java.version} (${java.vendor} ${java.vm.name} ${java.vm.version}) | ||
OS: ${os.name} ${os.version} ${os.arch} | ||
Locale: %s | ||
""", CsCLI.VERSION, CommandLine.VERSION, this.getLocale()) | ||
.split(System.lineSeparator()); | ||
} | ||
|
||
/** | ||
* Returns the tag, language, and country of the current environment locale. | ||
* The language and country names are given in English if available. | ||
* | ||
* @return The composed locale string sequence. | ||
*/ | ||
String getLocale() { | ||
var locale = Locale.getDefault(); | ||
var target = new Locale("en", "US"); | ||
return String.format("%s (%s %s)", locale.toLanguageTag(), | ||
locale.getDisplayLanguage(target), locale.getDisplayCountry(target)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package io.carbynestack.cli; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.ValueSource; | ||
|
||
import java.util.Locale; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class VersionTest { | ||
private final Version version = new Version(); | ||
|
||
@Test | ||
public void getLocale() { | ||
var locale = Locale.getDefault(); | ||
var target = new Locale("en", "US"); | ||
var result = version.getLocale(); | ||
assertThat(result).contains(locale.toLanguageTag()); | ||
assertThat(result).contains(locale.getDisplayLanguage(target)); | ||
assertThat(result).contains(locale.getDisplayCountry(target)); | ||
} | ||
|
||
@ParameterizedTest | ||
@ValueSource(strings = {"Carbyne Stack CLI", "Picocli", "Amphora", "Castor", "Ephemeral", "JVM", "OS", "Locale"}) | ||
public void getVersion(String sequence) { | ||
assertThat(version.getVersion()).anyMatch(line -> line.contains(sequence + ":")); | ||
} | ||
} |