Files
floci-cli/src/main/java/io/floci/cli/commands/VersionCommand.java
T
Hector Ventura de3ca7f171 feat(cli): add --json, --no-emoji, config profile edit and a warning for servers too old for the CLI (#62)
* feat(cli): add --json, --no-emoji, config profile edit and a warning for servers too old for the CLI

--json is shorthand for --output json. Marks are plain ASCII with --no-emoji, when output is piped and under NO_COLOR. config profile edit opens a profile in VISUAL or EDITOR and checks it still reads. status and version warn on stderr when the AWS server is older than the minimum the CLI supports.

Signed-off-by: Hector Ventura <hectorvent@gmail.com>

* feat(cli): keep the upgrade hint on the selected instance and read quoted editor commands

The old-server hint names the instance it is about and suggests a restart, which keeps that instance's settings. The update notice follows --no-emoji and NO_COLOR. VISUAL and EDITOR are split like a shell would, so a quoted path with spaces works.

Signed-off-by: Hector Ventura <hectorvent@gmail.com>

* feat(cli): keep Windows paths in editor values and say what to do for a pinned image

A backslash in VISUAL or EDITOR is an escape only before a space or a quote, so Windows paths come through intact. The old-server hint explains that restart keeps a pinned tag and how to change it.

Signed-off-by: Hector Ventura <hectorvent@gmail.com>

* feat(config): let profile edit open a profile that no longer parses

edit asked the store to parse the profile before opening it, so the one profile that needed repairing could not be opened. A file holding YAML's null is now reported as a profile without settings instead of failing with an exception.

Signed-off-by: Hector Ventura <hectorvent@gmail.com>

---------

Signed-off-by: Hector Ventura <hectorvent@gmail.com>
2026-10-11 09:12:44 -05:00

90 lines
3.0 KiB
Java

package io.floci.cli.commands;
import io.floci.cli.CliVersion;
import io.floci.cli.GlobalOptions;
import io.floci.cli.ProductProfile;
import io.floci.cli.ServerCompatibility;
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.util.LinkedHashMap;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.Callable;
@Command(
name = "version",
description = "Show CLI version, connected Floci AWS server version, and image digest",
mixinStandardHelpOptions = true
)
public class VersionCommand implements Callable<Integer> {
protected final ProductProfile profile;
@Mixin
protected GlobalOptions global;
public VersionCommand() {
this(ProductProfile.AWS);
}
protected VersionCommand(ProductProfile profile) {
this.profile = profile;
this.global = new GlobalOptions(profile);
}
@Override
public Integer call() {
Printer printer = global.printer();
String serverVersion = null;
String serverEdition = null;
String imageDigest = null;
var docker = new io.floci.cli.docker.DockerClient();
String effectiveEndpoint = global.resolvedEndpoint(docker);
FlociHttpClient client = new FlociHttpClient(effectiveEndpoint, profile);
try {
var info = client.info();
serverVersion = info.version();
serverEdition = info.edition();
} catch (Exception ignored) {}
// On stderr, so structured output stays one document.
ServerCompatibility.warning(profile, serverVersion, global.instanceSelector()).ifPresent(printer::warn);
// Try to read image digest from Docker (best-effort)
try {
imageDigest = docker.imageDigest(profile.image()).orElse(null);
} catch (Exception ignored) {}
Map<String, Object> data = new LinkedHashMap<>();
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);
if (printer.format() != OutputFormat.text) {
printer.structured(data);
return 0;
}
printer.println(Ansi.bold("Floci CLI") + " " + Ansi.gold(CliVersion.CLI_VERSION));
if (serverVersion != null) {
printer.println("Server: " + serverVersion + (serverEdition != null ? " (" + serverEdition + ")" : ""));
} else {
// 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);
}
return 0;
}
}