Skip to content

Commit

Permalink
Add version command (#23)
Browse files Browse the repository at this point in the history
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
grevend-bosch committed Oct 15, 2021
1 parent 340e817 commit d10625a
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/main/java/io/carbynestack/cli/CsCLI.java
Expand Up @@ -3,19 +3,21 @@
import picocli.CommandLine;
import picocli.CommandLine.Command;

import java.util.concurrent.Callable;
import static picocli.CommandLine.ScopeType.INHERIT;
import static picocli.CommandLine.usage;

@Command(name = "cs", version = "0.1-SNAPSHOT", mixinStandardHelpOptions = true)
public class CsCLI implements Callable<Integer> {
@Command(name = "cs", description = "Command Line Interface to interact with Carbyne Stack Virtual Clouds",
scope = INHERIT, mixinStandardHelpOptions = true, showAtFileInUsageHelp = true, versionProvider = Version.class)
public class CsCLI implements Runnable {
//The Carbyne Stack CLI semantic version number.
public static final String VERSION = "0.1.0";

public static void main(String[] args) {
System.exit(new CommandLine(new CsCLI()).execute(args));
}

@Override
public Integer call() {
System.out.println("Hello Carbyne Stack Community!");
return 0;
public void run() {
usage(this, System.out);
}

}
46 changes: 46 additions & 0 deletions src/main/java/io/carbynestack/cli/Version.java
@@ -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));
}
}
29 changes: 29 additions & 0 deletions src/test/java/io/carbynestack/cli/VersionTest.java
@@ -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 + ":"));
}
}

0 comments on commit d10625a

Please sign in to comment.