Issue #47: scaffold Java Gradle build
This commit is contained in:
+53
@@ -0,0 +1,53 @@
|
||||
package com.dohertylan.mxgateway.cli;
|
||||
|
||||
import com.dohertylan.mxgateway.client.MxGatewayClientVersion;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.concurrent.Callable;
|
||||
import picocli.CommandLine;
|
||||
import picocli.CommandLine.Command;
|
||||
import picocli.CommandLine.Model.CommandSpec;
|
||||
import picocli.CommandLine.Spec;
|
||||
|
||||
@Command(
|
||||
name = "mxgw-java",
|
||||
mixinStandardHelpOptions = true,
|
||||
description = "MXAccess Gateway Java test CLI.",
|
||||
subcommands = MxGatewayCli.VersionCommand.class)
|
||||
public final class MxGatewayCli implements Callable<Integer> {
|
||||
@Spec
|
||||
private CommandSpec spec;
|
||||
|
||||
public static void main(String[] args) {
|
||||
int exitCode = new CommandLine(new MxGatewayCli()).execute(args);
|
||||
System.exit(exitCode);
|
||||
}
|
||||
|
||||
public static int execute(PrintWriter out, PrintWriter err, String... args) {
|
||||
CommandLine commandLine = new CommandLine(new MxGatewayCli());
|
||||
commandLine.setOut(out);
|
||||
commandLine.setErr(err);
|
||||
return commandLine.execute(args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer call() {
|
||||
spec.commandLine().usage(spec.commandLine().getOut());
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Command(name = "version", description = "Prints the Java client scaffold version.")
|
||||
public static final class VersionCommand implements Callable<Integer> {
|
||||
@Spec
|
||||
private CommandSpec spec;
|
||||
|
||||
@Override
|
||||
public Integer call() {
|
||||
spec.commandLine().getOut().printf(
|
||||
"mxgateway-java %s gatewayProtocolVersion=%d workerProtocolVersion=%d%n",
|
||||
MxGatewayClientVersion.clientVersion(),
|
||||
MxGatewayClientVersion.gatewayProtocolVersion(),
|
||||
MxGatewayClientVersion.workerProtocolVersion());
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
package com.dohertylan.mxgateway.cli;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
final class MxGatewayCliTests {
|
||||
@Test
|
||||
void versionCommandPrintsProtocolVersions() {
|
||||
StringWriter output = new StringWriter();
|
||||
StringWriter errors = new StringWriter();
|
||||
|
||||
int exitCode = MxGatewayCli.execute(
|
||||
new PrintWriter(output, true),
|
||||
new PrintWriter(errors, true),
|
||||
"version");
|
||||
|
||||
assertEquals(0, exitCode);
|
||||
assertEquals("", errors.toString());
|
||||
assertTrue(output.toString().contains("mxgateway-java 0.1.0"));
|
||||
assertTrue(output.toString().contains("gatewayProtocolVersion=1"));
|
||||
assertTrue(output.toString().contains("workerProtocolVersion=1"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user