feat(java-cli): inject GalaxyClientFactory seam (behavior-preserving default)
This commit is contained in:
+67
-6
@@ -131,6 +131,11 @@ public final class MxGatewayCli implements Callable<Integer> {
|
||||
}
|
||||
|
||||
static CommandLine commandLine(MxGatewayCliClientFactory clientFactory) {
|
||||
return commandLine(clientFactory, new GrpcGalaxyClientFactory());
|
||||
}
|
||||
|
||||
static CommandLine commandLine(
|
||||
MxGatewayCliClientFactory clientFactory, GalaxyClientFactory galaxyClientFactory) {
|
||||
CommandLine commandLine = new CommandLine(new MxGatewayCli(clientFactory));
|
||||
commandLine.addSubcommand("version", new VersionCommand());
|
||||
commandLine.addSubcommand("open-session", new OpenSessionCommand(clientFactory));
|
||||
@@ -152,11 +157,11 @@ public final class MxGatewayCli implements Callable<Integer> {
|
||||
commandLine.addSubcommand("stream-alarms", new StreamAlarmsCommand(clientFactory));
|
||||
commandLine.addSubcommand("acknowledge-alarm", new AcknowledgeAlarmCommand(clientFactory));
|
||||
commandLine.addSubcommand("smoke", new SmokeCommand(clientFactory));
|
||||
commandLine.addSubcommand("galaxy-test-connection", new GalaxyTestConnectionCommand());
|
||||
commandLine.addSubcommand("galaxy-last-deploy", new GalaxyDeployTimeCommand());
|
||||
commandLine.addSubcommand("galaxy-discover", new GalaxyDiscoverCommand());
|
||||
commandLine.addSubcommand("galaxy-browse", new GalaxyBrowseCommand());
|
||||
commandLine.addSubcommand("galaxy-watch", new GalaxyWatchCommand());
|
||||
commandLine.addSubcommand("galaxy-test-connection", new GalaxyTestConnectionCommand(galaxyClientFactory));
|
||||
commandLine.addSubcommand("galaxy-last-deploy", new GalaxyDeployTimeCommand(galaxyClientFactory));
|
||||
commandLine.addSubcommand("galaxy-discover", new GalaxyDiscoverCommand(galaxyClientFactory));
|
||||
commandLine.addSubcommand("galaxy-browse", new GalaxyBrowseCommand(galaxyClientFactory));
|
||||
commandLine.addSubcommand("galaxy-watch", new GalaxyWatchCommand(galaxyClientFactory));
|
||||
commandLine.addSubcommand("batch", new BatchCommand(clientFactory));
|
||||
return commandLine;
|
||||
}
|
||||
@@ -359,14 +364,24 @@ public final class MxGatewayCli implements Callable<Integer> {
|
||||
}
|
||||
|
||||
abstract static class GalaxyCommand implements Callable<Integer> {
|
||||
final GalaxyClientFactory galaxyClientFactory;
|
||||
|
||||
@Mixin
|
||||
CommonOptions common = new CommonOptions();
|
||||
|
||||
@Option(names = "--json", description = "Write JSON output.")
|
||||
boolean json;
|
||||
|
||||
GalaxyCommand() {
|
||||
this(new GrpcGalaxyClientFactory());
|
||||
}
|
||||
|
||||
GalaxyCommand(GalaxyClientFactory galaxyClientFactory) {
|
||||
this.galaxyClientFactory = galaxyClientFactory;
|
||||
}
|
||||
|
||||
GalaxyRepositoryClient connect() {
|
||||
return GalaxyRepositoryClient.connect(common.resolved().toClientOptions());
|
||||
return galaxyClientFactory.connect(common.resolved().toClientOptions());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -375,6 +390,13 @@ public final class MxGatewayCli implements Callable<Integer> {
|
||||
aliases = {"galaxy-test"},
|
||||
description = "Calls GalaxyRepository.TestConnection.")
|
||||
static final class GalaxyTestConnectionCommand extends GalaxyCommand {
|
||||
GalaxyTestConnectionCommand() {
|
||||
}
|
||||
|
||||
GalaxyTestConnectionCommand(GalaxyClientFactory galaxyClientFactory) {
|
||||
super(galaxyClientFactory);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer call() {
|
||||
try (GalaxyRepositoryClient client = connect()) {
|
||||
@@ -399,6 +421,13 @@ public final class MxGatewayCli implements Callable<Integer> {
|
||||
aliases = {"galaxy-deploy-time"},
|
||||
description = "Calls GalaxyRepository.GetLastDeployTime.")
|
||||
static final class GalaxyDeployTimeCommand extends GalaxyCommand {
|
||||
GalaxyDeployTimeCommand() {
|
||||
}
|
||||
|
||||
GalaxyDeployTimeCommand(GalaxyClientFactory galaxyClientFactory) {
|
||||
super(galaxyClientFactory);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer call() {
|
||||
try (GalaxyRepositoryClient client = connect()) {
|
||||
@@ -423,6 +452,13 @@ public final class MxGatewayCli implements Callable<Integer> {
|
||||
|
||||
@Command(name = "galaxy-discover", description = "Calls GalaxyRepository.DiscoverHierarchy.")
|
||||
static final class GalaxyDiscoverCommand extends GalaxyCommand {
|
||||
GalaxyDiscoverCommand() {
|
||||
}
|
||||
|
||||
GalaxyDiscoverCommand(GalaxyClientFactory galaxyClientFactory) {
|
||||
super(galaxyClientFactory);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer call() {
|
||||
try (GalaxyRepositoryClient client = connect()) {
|
||||
@@ -458,6 +494,13 @@ public final class MxGatewayCli implements Callable<Integer> {
|
||||
name = "galaxy-browse",
|
||||
description = "Browses the Galaxy hierarchy via GalaxyRepository.BrowseChildren.")
|
||||
static final class GalaxyBrowseCommand extends GalaxyCommand {
|
||||
GalaxyBrowseCommand() {
|
||||
}
|
||||
|
||||
GalaxyBrowseCommand(GalaxyClientFactory galaxyClientFactory) {
|
||||
super(galaxyClientFactory);
|
||||
}
|
||||
|
||||
@Spec
|
||||
private CommandSpec spec;
|
||||
|
||||
@@ -718,6 +761,13 @@ public final class MxGatewayCli implements Callable<Integer> {
|
||||
name = "galaxy-watch",
|
||||
description = "Streams GalaxyRepository.WatchDeployEvents until cancelled.")
|
||||
static final class GalaxyWatchCommand extends GalaxyCommand {
|
||||
GalaxyWatchCommand() {
|
||||
}
|
||||
|
||||
GalaxyWatchCommand(GalaxyClientFactory galaxyClientFactory) {
|
||||
super(galaxyClientFactory);
|
||||
}
|
||||
|
||||
@Option(
|
||||
names = "--last-seen-deploy-time",
|
||||
description =
|
||||
@@ -1725,6 +1775,10 @@ public final class MxGatewayCli implements Callable<Integer> {
|
||||
}
|
||||
}
|
||||
|
||||
interface GalaxyClientFactory {
|
||||
GalaxyRepositoryClient connect(MxGatewayClientOptions options);
|
||||
}
|
||||
|
||||
interface MxGatewayCliClientFactory {
|
||||
MxGatewayCliClient connect(CommonOptions options);
|
||||
}
|
||||
@@ -1781,6 +1835,13 @@ public final class MxGatewayCli implements Callable<Integer> {
|
||||
MxEventStream streamEventsAfter(long afterWorkerSequence);
|
||||
}
|
||||
|
||||
static final class GrpcGalaxyClientFactory implements GalaxyClientFactory {
|
||||
@Override
|
||||
public GalaxyRepositoryClient connect(MxGatewayClientOptions options) {
|
||||
return GalaxyRepositoryClient.connect(options);
|
||||
}
|
||||
}
|
||||
|
||||
static final class GrpcMxGatewayCliClientFactory implements MxGatewayCliClientFactory {
|
||||
@Override
|
||||
public MxGatewayCliClient connect(CommonOptions options) {
|
||||
|
||||
Reference in New Issue
Block a user