refactor!: unify the four product command trees behind ProductProfile (#16)

* refactor!: unify the four product command trees behind ProductProfile

Every shared command now has ONE implementation in commands/,
parameterized by ProductProfile (the single source of per-product
config: endpoint, container, image, env prefix, control prefix,
display name). The gcp/az/oci command classes become ~8-line shims
(GcpStartCommand extends StartCommand { super(ProductProfile.GCP); })
that carry only their per-product help description; the three
near-identical *GlobalOptions clones are deleted. Each product tree
drops from ~1,360 to ~530 lines and copy-drift becomes impossible.

Mechanics: per-product option defaults are constructor-set field
values rendered in help via ${DEFAULT-VALUE} (annotation defaults are
compile-time constants); commands pre-initialize their GlobalOptions
mixin with the profile (picocli uses a non-null mixin field instance
as-is). Verified against a captured baseline of 480 CLI outputs
(every --help x 5 trees, env/status/doctor JSON, exit codes, routing)
plus new pinning tests: ProductProfileTest, ProductTreesParsingTest,
DoctorCheckListTest, GlobalOptionsTest.

Behavior changes, all deliberate:
- snapshot commands in gcp/az/oci trees now perform the real
  /snapshots API calls with graceful degradation and exit 1 while the
  server lacks the endpoints (previously: note + exit 0)
- product logs/services gained --service/--mode, and services now
  resolves the endpoint from the container port mapping in all trees
- the AWS tree brands itself 'Floci AWS' in banners and help,
  matching the other products
- snapshot errors link the product issue tracker instead of TODO.md
- completion generates from spec.root() instead of a hardcoded
  FlociCli instance (output unchanged)

BREAKING CHANGE: 'floci gcp|az|oci snapshot export/import' (and bare
'floci snapshot ...' with a non-AWS default product) now exit 1
instead of 0 while server-side snapshot support is pending; CI
scripts relying on the silent success of stubbed snapshot commands
will fail.

* fix: snapshot save/load/list/delete resolve the container host port

Same port auto-detection status/services/wait use — a container started
with --port <n> is now reachable by the snapshot commands without an
explicit --endpoint. Applies to all four trees via the unified base
commands.
This commit is contained in:
Hector Ventura authored and GitHub committed 2026-07-28 21:45:52 -05:00
1 parent 0a65de2303
commit 6dc8fc9df4
100 files changed
+1190 -3283

No files matched your search

@@ -1,73 +1,17 @@
package io.floci.cli.commands.az;
import io.floci.cli.AzGlobalOptions;
import io.floci.cli.docker.DockerClient;
import io.floci.cli.docker.DockerException;
import io.floci.cli.output.Ansi;
import io.floci.cli.output.Printer;
import picocli.CommandLine.*;
import java.util.concurrent.Callable;
import io.floci.cli.ProductProfile;
import io.floci.cli.commands.StopCommand;
import picocli.CommandLine.Command;
@Command(
name = "stop",
description = "Stop the Floci Azure container",
mixinStandardHelpOptions = true
)
public class AzStopCommand implements Callable<Integer> {
public class AzStopCommand extends StopCommand {
@Mixin
AzGlobalOptions global;
@Option(names = {"--remove", "-r"}, description = "Remove the container after stopping")
boolean remove;
@Option(names = {"--timeout"}, description = "Seconds to wait before forcefully killing (default: 10)", defaultValue = "10", paramLabel = "<seconds>")
int timeout;
@Override
public Integer call() {
Printer printer = global.printer();
DockerClient docker = new DockerClient();
try {
var info = docker.inspectContainer(global.container);
if (info.isEmpty()) {
printer.error("Container '" + global.container + "' not found.\nRun 'floci az start' to launch one.");
return 1;
}
if (!"running".equals(info.get().state())) {
printer.println(Ansi.yellow("Container '" + global.container + "' is not running (state: " + info.get().state() + ")"));
if (remove) {
docker.removeContainer(global.container);
printer.println("Container removed.");
}
return 0;
}
} catch (DockerException e) {
printer.error("Failed to inspect container: " + e.getMessage());
return 1;
}
try {
printer.println("Stopping " + Ansi.gold("Floci Azure") + " container '" + global.container + "'...");
docker.stopContainer(global.container, timeout);
printer.println(Ansi.green("Stopped."));
} catch (DockerException e) {
printer.error("Failed to stop container: " + e.getMessage());
return 1;
}
if (remove) {
try {
docker.removeContainer(global.container);
printer.println("Container removed.");
} catch (DockerException e) {
printer.error("Failed to remove container: " + e.getMessage());
return 1;
}
}
return 0;
public AzStopCommand() {
super(ProductProfile.AZ);
}
}