From e2b1a6686a84a88abcd34c51b651084bab3bd855 Mon Sep 17 00:00:00 2001 From: Joseph Doherty Date: Tue, 16 Jun 2026 17:18:47 -0400 Subject: [PATCH] feat(java-cli): inject GalaxyClientFactory seam (behavior-preserving default) --- .../zb/mom/ww/mxgateway/cli/MxGatewayCli.java | 73 +++++++++++++++++-- 1 file changed, 67 insertions(+), 6 deletions(-) diff --git a/clients/java/zb-mom-ww-mxgateway-cli/src/main/java/com/zb/mom/ww/mxgateway/cli/MxGatewayCli.java b/clients/java/zb-mom-ww-mxgateway-cli/src/main/java/com/zb/mom/ww/mxgateway/cli/MxGatewayCli.java index 7364ca1..30361a0 100644 --- a/clients/java/zb-mom-ww-mxgateway-cli/src/main/java/com/zb/mom/ww/mxgateway/cli/MxGatewayCli.java +++ b/clients/java/zb-mom-ww-mxgateway-cli/src/main/java/com/zb/mom/ww/mxgateway/cli/MxGatewayCli.java @@ -131,6 +131,11 @@ public final class MxGatewayCli implements Callable { } 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 { 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 { } abstract static class GalaxyCommand implements Callable { + 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 { 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 { 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 { @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 { 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 { 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 { } } + interface GalaxyClientFactory { + GalaxyRepositoryClient connect(MxGatewayClientOptions options); + } + interface MxGatewayCliClientFactory { MxGatewayCliClient connect(CommonOptions options); } @@ -1781,6 +1835,13 @@ public final class MxGatewayCli implements Callable { 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) {