Add spring cloud --version option

fixes gh-33
This commit is contained in:
Spencer Gibb
2016-10-03 15:12:17 -06:00
parent 44a5adbf6f
commit 33ca198cca
2 changed files with 17 additions and 2 deletions

View File

@@ -61,6 +61,7 @@ public class LauncherCommand extends OptionParsingCommand {
EXAMPLES.add(new HelpExample("Launch Config Server and Eureka",
"spring cloud configserver eureka"));
EXAMPLES.add(new HelpExample("List deployable apps", "spring cloud --list"));
EXAMPLES.add(new HelpExample("Show version", "spring cloud --version"));
}
public LauncherCommand() {
@@ -77,6 +78,7 @@ public class LauncherCommand extends OptionParsingCommand {
private OptionSpec<Void> debugOption;
private OptionSpec<Void> listOption;
private OptionSpec<Void> versionOption;
@Override
protected void options() {
@@ -87,11 +89,16 @@ public class LauncherCommand extends OptionParsingCommand {
"Debug logging for the deployer");
this.listOption = option(Arrays.asList("list", "l"),
"List the deployables (don't launch anything)");
this.versionOption = option(Arrays.asList("version", "v"),
"Show the version (don't launch anything)");
}
@Override
protected synchronized ExitStatus run(OptionSet options) throws Exception {
if (options.has(this.versionOption)) {
System.out.println("Spring Cloud CLI v"+getVersion());
return ExitStatus.OK;
}
try {
URLClassLoader classLoader = populateClassloader(options);
@@ -106,7 +113,8 @@ public class LauncherCommand extends OptionParsingCommand {
thread.join();
}
catch (Exception e) {
e.printStackTrace();
log.error("Error running spring cloud", e);
return ExitStatus.ERROR;
}
return ExitStatus.OK;

View File

@@ -20,6 +20,7 @@ import org.junit.Rule;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.startsWith;
import static org.junit.Assert.assertThat;
/**
@@ -41,4 +42,10 @@ public class LauncherCommandTests {
new LauncherCommand().run("--list", "--", "--spring.profiles.active=test");
assertThat(output.toString(), containsString("foo"));
}
@Test
public void testVersion() throws Exception {
new LauncherCommand().run("--version");
assertThat(output.toString(), startsWith("Spring Cloud CLI v"));
}
}