mirror of
https://github.com/floci-io/floci-cli.git
synced 2026-11-22 21:50:47 -05:00
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:
1 parent
0a65de2303
commit
6dc8fc9df4
100 files changed
+1190
-3283
No files matched your search
@@ -1,41 +1,39 @@
|
||||
package io.floci.cli.commands;
|
||||
|
||||
import io.floci.cli.CliVersion;
|
||||
import io.floci.cli.GlobalOptions;
|
||||
import io.floci.cli.ProductProfile;
|
||||
import io.floci.cli.http.FlociHttpClient;
|
||||
import io.floci.cli.output.Ansi;
|
||||
import io.floci.cli.output.OutputFormat;
|
||||
import io.floci.cli.output.Printer;
|
||||
import picocli.CommandLine.*;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
@Command(
|
||||
name = "version",
|
||||
description = "Show CLI version, connected server version, and image digest",
|
||||
description = "Show CLI version, connected Floci AWS server version, and image digest",
|
||||
mixinStandardHelpOptions = true
|
||||
)
|
||||
public class VersionCommand implements Callable<Integer> {
|
||||
|
||||
public static final String CLI_VERSION = loadVersion();
|
||||
|
||||
private static String loadVersion() {
|
||||
try (InputStream is = VersionCommand.class.getResourceAsStream("/io/floci/cli/version.properties")) {
|
||||
if (is == null) return "unknown";
|
||||
Properties props = new Properties();
|
||||
props.load(is);
|
||||
return props.getProperty("version", "unknown");
|
||||
} catch (Exception e) {
|
||||
return "unknown";
|
||||
}
|
||||
}
|
||||
protected final ProductProfile profile;
|
||||
|
||||
@Mixin
|
||||
GlobalOptions global;
|
||||
protected GlobalOptions global;
|
||||
|
||||
public VersionCommand() {
|
||||
this(ProductProfile.AWS);
|
||||
}
|
||||
|
||||
protected VersionCommand(ProductProfile profile) {
|
||||
this.profile = profile;
|
||||
this.global = new GlobalOptions(profile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer call() {
|
||||
@@ -48,7 +46,7 @@ public class VersionCommand implements Callable<Integer> {
|
||||
var docker = new io.floci.cli.docker.DockerClient();
|
||||
String effectiveEndpoint = global.resolvedEndpoint(docker);
|
||||
|
||||
FlociHttpClient client = new FlociHttpClient(effectiveEndpoint);
|
||||
FlociHttpClient client = new FlociHttpClient(effectiveEndpoint, profile.controlPrefix());
|
||||
try {
|
||||
var info = client.info();
|
||||
serverVersion = info.version();
|
||||
@@ -57,11 +55,11 @@ public class VersionCommand implements Callable<Integer> {
|
||||
|
||||
// Try to read image digest from Docker (best-effort)
|
||||
try {
|
||||
imageDigest = docker.imageDigest("floci/floci").orElse(null);
|
||||
imageDigest = docker.imageDigest(profile.image()).orElse(null);
|
||||
} catch (Exception ignored) {}
|
||||
|
||||
Map<String, Object> data = new LinkedHashMap<>();
|
||||
data.put("cli", CLI_VERSION);
|
||||
data.put("cli", CliVersion.CLI_VERSION);
|
||||
data.put("server", Optional.ofNullable(serverVersion).orElse("unavailable"));
|
||||
data.put("edition", Optional.ofNullable(serverEdition).orElse(""));
|
||||
if (imageDigest != null) data.put("digest", imageDigest);
|
||||
@@ -71,11 +69,13 @@ public class VersionCommand implements Callable<Integer> {
|
||||
return 0;
|
||||
}
|
||||
|
||||
printer.println(Ansi.bold("Floci CLI") + " " + Ansi.gold(CLI_VERSION));
|
||||
printer.println(Ansi.bold("Floci CLI") + " " + Ansi.gold(CliVersion.CLI_VERSION));
|
||||
if (serverVersion != null) {
|
||||
printer.println("Server: " + serverVersion + (serverEdition != null ? " (" + serverEdition + ")" : ""));
|
||||
} else {
|
||||
printer.println("Server: " + Ansi.gray("not reachable at " + global.endpoint));
|
||||
// Effective endpoint (port auto-detected) — the gcp/az/oci trees always did
|
||||
// this; the old AWS copy printed the raw --endpoint value.
|
||||
printer.println("Server: " + Ansi.gray("not reachable at " + effectiveEndpoint));
|
||||
}
|
||||
if (imageDigest != null) {
|
||||
printer.println("Image: " + imageDigest);
|
||||
|
||||
Reference in new issue
Block a user