Skip to content

Commit

Permalink
Merge pull request #171 from marklogic/feature/version-json
Browse files Browse the repository at this point in the history
Converting verbose version info into a JSON object
  • Loading branch information
rjrudin authored Jul 11, 2024
2 parents e853a85 + 46bef4c commit ea4b6b7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
17 changes: 13 additions & 4 deletions flux-cli/src/main/java/com/marklogic/flux/impl/VersionCommand.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.marklogic.flux.impl;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.spark.sql.SparkSession;
import picocli.CommandLine;

Expand All @@ -21,11 +22,19 @@ public class VersionCommand implements Command {
@Override
public Optional<Preview> execute(SparkSession session) {
ResourceBundle versionProperties = getResourceBundle();
commandLine.getOut().println("Flux version: " + versionProperties.getString("version"));
commandLine.getOut().println("Java version: " + System.getProperty("java.version"));
commandLine.getOut().println("Spark version: " + session.version());
final String version = versionProperties.getString("version");
final String javaVersion = System.getProperty("java.version");
final String sparkVersion = session.version();
if (verbose) {
commandLine.getOut().println("Build time: " + versionProperties.getString("buildTime"));
commandLine.getOut().println(new ObjectMapper().createObjectNode()
.put("fluxVersion", version)
.put("buildTime", versionProperties.getString("buildTime"))
.put("javaVersion", javaVersion)
.put("sparkVersion", sparkVersion));
} else {
commandLine.getOut().println("Flux version: " + version);
commandLine.getOut().println("Java version: " + javaVersion);
commandLine.getOut().println("Spark version: " + sparkVersion);
}
return Optional.empty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ void test() {
@Test
void verbose() {
String stdout = runAndReturnStdout(() -> run("version", "--verbose"));
assertTrue(stdout.contains("Build time:"), "Unexpected stdout: " + stdout);
assertTrue(stdout.contains("\"buildTime\""), "When using --verbose, the output should be a JSON object " +
"that includes the build time for performance tests and can thus be easily parsed by another program; " +
"unexpected stdout: " + stdout);
}
}

0 comments on commit ea4b6b7

Please sign in to comment.