chore: first commit

This commit is contained in:
Hector Ventura committed 2026-05-12 17:10:46 -05:00
commit aef1df595f
69 files changed
+3697

No files matched your search

@@ -0,0 +1,43 @@
package io.floci.cli.commands;
import io.floci.cli.GlobalOptions;
import io.floci.cli.output.Printer;
import picocli.AutoComplete;
import picocli.CommandLine;
import picocli.CommandLine.*;
import java.util.concurrent.Callable;
@Command(
name = "completion",
description = "Generate shell completion scripts",
mixinStandardHelpOptions = true
)
public class CompletionCommand implements Callable<Integer> {
@Mixin
GlobalOptions global;
@Parameters(index = "0", description = "Shell type: bash, zsh, fish, powershell", paramLabel = "bash|zsh|fish|powershell")
String shell;
@Override
public Integer call() {
Printer printer = global.printer();
CommandLine root = new CommandLine(new io.floci.cli.FlociCli());
String script = switch (shell.toLowerCase()) {
case "bash" -> AutoComplete.bash("floci", root);
case "zsh" -> AutoComplete.bash("floci", root); // zsh is bash-compatible; picocli bash script works for zsh too
default -> {
printer.error("Shell '" + shell + "' not supported. Supported: bash, zsh\n" +
"For fish and powershell, track https://github.com/floci-io/floci-cli/issues");
yield null;
}
};
if (script == null) return 1;
System.out.print(script);
return 0;
}
}
@@ -0,0 +1,106 @@
package io.floci.cli.commands;
import io.floci.cli.GlobalOptions;
import io.floci.cli.doctor.Check;
import io.floci.cli.doctor.CheckResult;
import io.floci.cli.doctor.CheckStatus;
import io.floci.cli.doctor.checks.*;
import io.floci.cli.output.Ansi;
import io.floci.cli.output.OutputFormat;
import io.floci.cli.output.Printer;
import picocli.CommandLine.*;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;
@Command(
name = "doctor",
description = "Run environment diagnostics for Floci",
mixinStandardHelpOptions = true
)
public class DoctorCommand implements Callable<Integer> {
@Mixin
GlobalOptions global;
@Option(names = {"--check"}, description = "Run only a specific check by name", paramLabel = "<name>")
String checkName;
@Option(names = {"--fix"}, description = "Attempt to auto-fix fixable issues")
boolean fix;
private static final List<Check> ALL_CHECKS = List.of(
new DockerInstalledCheck(),
new DockerDaemonCheck(),
new DockerSocketCheck(),
new DockerVersionCheck(),
new PortAvailableCheck(),
new ImagePresentCheck(),
new ImageVersionCheck(),
new ContainerRunningCheck(),
new EndpointReachableCheck(),
new AwsCliEndpointCheck(),
new AwsCliS3PathStyleCheck(),
new SdkRustS3XmlCheck(),
new SdkGoEndpointCheck()
);
@Override
public Integer call() {
Printer printer = global.printer();
List<CheckResult> results = new ArrayList<>();
printer.println(Ansi.bold("Floci Doctor") + " — checking your environment");
printer.println("");
for (Check check : ALL_CHECKS) {
CheckResult result = check.run(global.endpoint, global.container);
if (checkName != null && !result.name().equals(checkName)) continue;
results.add(result);
printResult(printer, result);
}
if (printer.format() != OutputFormat.text) {
List<Map<String, Object>> structured = new ArrayList<>();
for (CheckResult r : results) {
Map<String, Object> m = new LinkedHashMap<>();
m.put("name", r.name());
m.put("status", r.status().name());
m.put("message", r.message());
if (r.fix() != null) m.put("fix", r.fix());
structured.add(m);
}
printer.structured(structured);
return 0;
}
long fails = results.stream().filter(r -> r.status() == CheckStatus.fail).count();
long warns = results.stream().filter(r -> r.status() == CheckStatus.warn).count();
printer.println("");
if (fails == 0 && warns == 0) {
printer.println(Ansi.green("All checks passed."));
} else {
printer.println(fails + " issue(s) found (" + fails + " fail, " + warns + " warn)."
+ (fix ? "" : " Run with --fix to auto-resolve fixable issues."));
}
return fails > 0 ? 1 : 0;
}
private void printResult(Printer printer, CheckResult r) {
String icon = switch (r.status()) {
case ok -> Ansi.green("✓");
case warn -> Ansi.yellow("⚠");
case fail -> Ansi.red("✗");
};
String namePadded = String.format("%-26s", r.name());
printer.println(" " + icon + " " + namePadded + " " + r.message());
if (r.fix() != null) {
printer.println(" " + Ansi.gray("Fix: " + r.fix()));
}
}
}
@@ -0,0 +1,61 @@
package io.floci.cli.commands;
import io.floci.cli.GlobalOptions;
import io.floci.cli.docker.DockerClient;
import io.floci.cli.docker.DockerException;
import io.floci.cli.output.Printer;
import picocli.CommandLine.*;
import java.util.concurrent.Callable;
@Command(
name = "logs",
description = "Fetch logs from the Floci container",
mixinStandardHelpOptions = true
)
public class LogsCommand implements Callable<Integer> {
@Mixin
GlobalOptions global;
@Option(names = {"--follow", "-f"}, description = "Follow log output")
boolean follow;
@Option(names = {"--tail"}, description = "Number of lines from the end (0 = all)", defaultValue = "100", paramLabel = "<n>")
int tail;
@Option(names = {"--since"}, description = "Show logs since duration (e.g. 5m, 1h) or timestamp", paramLabel = "<duration>")
String since;
@Option(names = {"--service"}, description = "Filter to a specific service (not yet supported; requires server-side filtering)", paramLabel = "<name>")
String service;
@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 start' to launch one.");
return 1;
}
} catch (DockerException e) {
printer.error("Failed to inspect container: " + e.getMessage());
return 1;
}
if (service != null) {
printer.warn("--service filtering is not yet supported. Showing all container logs.");
}
try {
docker.streamLogs(global.container, follow, tail, since);
return 0;
} catch (DockerException e) {
printer.error("Failed to fetch logs: " + e.getMessage());
return 1;
}
}
}
@@ -0,0 +1,41 @@
package io.floci.cli.commands;
import io.floci.cli.GlobalOptions;
import io.floci.cli.output.Printer;
import picocli.CommandLine.*;
import java.util.concurrent.Callable;
@Command(
name = "restart",
description = "Stop and restart the Floci container",
mixinStandardHelpOptions = true
)
public class RestartCommand implements Callable<Integer> {
@Mixin
GlobalOptions global;
@Override
public Integer call() {
Printer printer = global.printer();
StopCommand stop = new StopCommand();
stop.global = global;
stop.remove = false;
stop.timeout = 10;
int stopResult = stop.call();
if (stopResult != 0) return stopResult;
// Minimal wait to avoid port-already-in-use races
try { Thread.sleep(1000); } catch (InterruptedException e) { Thread.currentThread().interrupt(); }
StartCommand start = new StartCommand();
start.global = global;
start.port = 4566;
start.pull = "missing";
start.image = "floci/floci:latest";
start.detach = false;
return start.call();
}
}
@@ -0,0 +1,58 @@
package io.floci.cli.commands;
import io.floci.cli.GlobalOptions;
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.Arrays;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;
@Command(
name = "services",
description = "List services available in the running Floci instance",
mixinStandardHelpOptions = true
)
public class ServicesCommand implements Callable<Integer> {
@Mixin
GlobalOptions global;
@Option(names = {"--mode"}, description = "Filter mode: docker, in-process, all (default: all)", defaultValue = "all", paramLabel = "docker|in-process|all")
String mode;
@Override
public Integer call() {
Printer printer = global.printer();
FlociHttpClient client = new FlociHttpClient(global.endpoint);
List<String> services;
try {
var health = client.health();
services = Arrays.asList(health.services());
} catch (Exception e) {
printer.error("Could not reach Floci at " + global.endpoint + ".\nIs Floci running? Try 'floci start'.");
return 1;
}
if (printer.format() != OutputFormat.text) {
printer.structured(Map.of("services", services, "count", services.size()));
return 0;
}
printer.println(Ansi.bold("Floci Services") + " " + Ansi.gray("(" + services.size() + " enabled)"));
printer.println("");
for (String svc : services) {
printer.println(" " + Ansi.green("✓") + " " + svc);
}
if (services.isEmpty()) {
printer.println(" " + Ansi.gray("(no services reported)"));
}
return 0;
}
}
@@ -0,0 +1,114 @@
package io.floci.cli.commands;
import io.floci.cli.GlobalOptions;
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.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;
@Command(
name = "start",
description = "Start the Floci container",
mixinStandardHelpOptions = true
)
public class StartCommand implements Callable<Integer> {
@Mixin
GlobalOptions global;
@Option(names = {"--port"}, description = "Host port to bind (default: 4566)", defaultValue = "4566", paramLabel = "<port>")
int port;
@Option(names = {"--persist"}, description = "Host directory for persistent state", paramLabel = "<dir>")
String persistDir;
@Option(names = {"--services"}, description = "Comma-separated list of services to enable", paramLabel = "<csv>")
String services;
@Option(names = {"--detach"}, description = "Return immediately without waiting for readiness")
boolean detach;
@Option(names = {"--image"}, description = "Image reference to use (default: floci/floci:latest)", defaultValue = "floci/floci:latest", paramLabel = "<ref>")
String image;
@Option(names = {"--pull"}, description = "Image pull policy: always, missing, never", defaultValue = "missing", paramLabel = "always|missing|never")
String pull;
@Override
public Integer call() {
Printer printer = global.printer();
DockerClient docker = new DockerClient();
// Verify docker is available
if (!DockerClient.isInstalled()) {
printer.error("docker binary not found in PATH.\nInstall Docker Desktop from https://docs.docker.com/get-docker/");
return 1;
}
// Check if container already exists
try {
var existing = docker.inspectContainer(global.container);
if (existing.isPresent()) {
String state = existing.get().state();
if ("running".equals(state)) {
printer.error("Container '" + global.container + "' is already running.\nRun 'floci stop' first or pass --container <name> to use a different name.");
return 1;
}
// Remove stopped container so we can start fresh
printer.println(Ansi.gray("Removing stopped container '" + global.container + "'..."));
docker.removeContainer(global.container);
}
} catch (DockerException e) {
printer.error("Failed to inspect container: " + e.getMessage());
return 1;
}
// Pull image if needed
try {
printer.println(Ansi.gray("Checking image " + image + " (policy: " + pull + ")..."));
docker.pull(image, pull);
} catch (DockerException e) {
printer.error("Failed to pull image: " + e.getMessage() + "\nRun 'floci start --pull never' to skip pulling.");
return 1;
}
// Build docker run arguments
List<String> args = new ArrayList<>();
args.addAll(List.of("-d", "--name", global.container));
args.addAll(List.of("-p", port + ":4566"));
args.addAll(List.of("-v", "/var/run/docker.sock:/var/run/docker.sock"));
if (persistDir != null) {
args.addAll(List.of("-v", persistDir + ":/var/lib/floci"));
}
if (services != null && !services.isBlank()) {
args.addAll(List.of("-e", "FLOCI_SERVICES=" + services));
}
args.add(image);
try {
printer.println("Starting " + Ansi.gold("Floci") + " container...");
String id = docker.startContainer(args);
printer.println(Ansi.green("Container started") + " (" + id.substring(0, Math.min(12, id.length())) + ")");
} catch (DockerException e) {
printer.error("Failed to start container: " + e.getMessage());
return 1;
}
if (detach) {
printer.println(Ansi.gray("Detached. Run 'floci wait' to poll for readiness."));
return 0;
}
// Wait for readiness
printer.println(Ansi.gray("Waiting for Floci to be ready..."));
WaitCommand wait = new WaitCommand();
wait.global = global;
wait.timeout = "30s";
return wait.call();
}
}
@@ -0,0 +1,98 @@
package io.floci.cli.commands;
import io.floci.cli.GlobalOptions;
import io.floci.cli.docker.DockerClient;
import io.floci.cli.docker.DockerException;
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 = "status",
description = "Show Floci container and server status",
mixinStandardHelpOptions = true
)
public class StatusCommand implements Callable<Integer> {
@Mixin
GlobalOptions global;
@Override
public Integer call() {
Printer printer = global.printer();
DockerClient docker = new DockerClient();
// Gather container info
String containerState = "not found";
String containerImage = "";
String containerPorts = "";
try {
Optional<DockerClient.ContainerInfo> info = docker.inspectContainer(global.container);
if (info.isPresent()) {
containerState = info.get().state();
containerImage = info.get().image();
containerPorts = info.get().ports();
}
} catch (DockerException e) {
containerState = "error: " + e.getMessage();
}
// Gather server info
String serverVersion = "unavailable";
String serverEdition = "";
boolean reachable = false;
FlociHttpClient client = new FlociHttpClient(global.endpoint);
try {
var health = client.health();
serverVersion = health.version();
serverEdition = health.edition();
reachable = true;
} catch (Exception ignored) {}
Map<String, Object> data = new LinkedHashMap<>();
data.put("container", global.container);
data.put("state", containerState);
data.put("image", containerImage);
data.put("ports", containerPorts);
data.put("endpoint", global.endpoint);
data.put("reachable", reachable);
data.put("version", serverVersion);
data.put("edition", serverEdition);
if (printer.format() != OutputFormat.text) {
printer.structured(data);
return 0;
}
printer.println(Ansi.bold("Floci Status"));
printer.println("");
String stateColor = switch (containerState) {
case "running" -> Ansi.green(containerState);
case "not found" -> Ansi.gray(containerState);
default -> Ansi.red(containerState);
};
printer.println(" Container: " + global.container + " " + stateColor);
if (!containerImage.isBlank()) printer.println(" Image: " + containerImage);
if (!containerPorts.isBlank()) printer.println(" Ports: " + containerPorts);
printer.println(" Endpoint: " + global.endpoint);
printer.println(" Reachable: " + (reachable ? Ansi.green("yes") : Ansi.red("no")));
if (reachable) {
printer.println(" Version: " + serverVersion);
if (!serverEdition.isBlank()) printer.println(" Edition: " + serverEdition);
}
if (!reachable && !"running".equals(containerState)) {
printer.println("");
printer.println(Ansi.gray("Run 'floci start' to launch Floci."));
}
return 0;
}
}
@@ -0,0 +1,73 @@
package io.floci.cli.commands;
import io.floci.cli.GlobalOptions;
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;
@Command(
name = "stop",
description = "Stop the Floci container",
mixinStandardHelpOptions = true
)
public class StopCommand implements Callable<Integer> {
@Mixin
GlobalOptions 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 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") + " 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;
}
}
@@ -0,0 +1,71 @@
package io.floci.cli.commands;
import io.floci.cli.GlobalOptions;
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 server version, and image digest",
mixinStandardHelpOptions = true
)
public class VersionCommand implements Callable<Integer> {
public static final String CLI_VERSION = "0.1.0";
@Mixin
GlobalOptions global;
@Override
public Integer call() {
Printer printer = global.printer();
String serverVersion = null;
String serverEdition = null;
String imageDigest = null;
FlociHttpClient client = new FlociHttpClient(global.endpoint);
try {
var info = client.info();
serverVersion = info.version();
serverEdition = info.edition();
} catch (Exception ignored) {}
// Try to read image digest from Docker (best-effort)
try {
var docker = new io.floci.cli.docker.DockerClient();
imageDigest = docker.imageDigest("floci/floci").orElse(null);
} catch (Exception ignored) {}
Map<String, Object> data = new LinkedHashMap<>();
data.put("cli", 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(CLI_VERSION));
if (serverVersion != null) {
printer.println("Server: " + serverVersion + (serverEdition != null ? " (" + serverEdition + ")" : ""));
} else {
printer.println("Server: " + Ansi.gray("not reachable at " + global.endpoint));
}
if (imageDigest != null) {
printer.println("Image: " + imageDigest);
}
return 0;
}
}
@@ -0,0 +1,79 @@
package io.floci.cli.commands;
import io.floci.cli.GlobalOptions;
import io.floci.cli.http.FlociHttpClient;
import io.floci.cli.output.Ansi;
import io.floci.cli.output.Printer;
import picocli.CommandLine.*;
import java.time.Duration;
import java.time.Instant;
import java.util.concurrent.Callable;
@Command(
name = "wait",
description = "Wait until Floci is ready to accept requests",
mixinStandardHelpOptions = true
)
public class WaitCommand implements Callable<Integer> {
@Mixin
GlobalOptions global;
@Option(names = {"--timeout"}, description = "Maximum time to wait (e.g. 30s, 2m)", defaultValue = "30s", paramLabel = "<duration>")
String timeout;
@Option(names = {"--service"}, description = "Wait until a specific service is enabled", paramLabel = "<name>")
String service;
@Override
public Integer call() {
Printer printer = global.printer();
long timeoutMillis = parseDuration(timeout);
FlociHttpClient client = new FlociHttpClient(global.endpoint);
Instant deadline = Instant.now().plusMillis(timeoutMillis);
while (Instant.now().isBefore(deadline)) {
if (isReady(client, service)) {
printer.println(Ansi.green("Floci is ready") + " (" + global.endpoint + ")");
return 0;
}
printSpinner(printer, deadline);
try { Thread.sleep(500); } catch (InterruptedException e) {
Thread.currentThread().interrupt();
break;
}
}
printer.error("Timed out waiting for Floci after " + timeout + ".\nIs the container running? Try 'floci status'.");
return 1;
}
private boolean isReady(FlociHttpClient client, String requiredService) {
try {
var health = client.health();
if (requiredService == null) return true;
for (String s : health.services()) {
if (s.equalsIgnoreCase(requiredService)) return true;
}
return false;
} catch (Exception e) {
return false;
}
}
private void printSpinner(Printer printer, Instant deadline) {
long remaining = Duration.between(Instant.now(), deadline).toSeconds();
printer.print("\r" + Ansi.gray("Waiting... (" + remaining + "s remaining)") + " ");
}
public static long parseDuration(String s) {
if (s == null || s.isBlank()) return 30_000;
s = s.trim().toLowerCase();
if (s.endsWith("ms")) return Long.parseLong(s.substring(0, s.length() - 2));
if (s.endsWith("s")) return Long.parseLong(s.substring(0, s.length() - 1)) * 1000;
if (s.endsWith("m")) return Long.parseLong(s.substring(0, s.length() - 1)) * 60_000;
if (s.endsWith("h")) return Long.parseLong(s.substring(0, s.length() - 1)) * 3_600_000;
return Long.parseLong(s) * 1000;
}
}
@@ -0,0 +1,23 @@
package io.floci.cli.commands.config;
import picocli.CommandLine;
import picocli.CommandLine.*;
@Command(
name = "config",
description = "Manage Floci configuration",
mixinStandardHelpOptions = true,
subcommands = {
ConfigShowCommand.class,
ConfigValidateCommand.class,
ConfigProfileCommand.class,
HelpCommand.class
}
)
public class ConfigCommand implements Runnable {
@Override
public void run() {
new CommandLine(this).usage(System.out);
}
}
@@ -0,0 +1,118 @@
package io.floci.cli.commands.config;
import io.floci.cli.GlobalOptions;
import io.floci.cli.config.Profile;
import io.floci.cli.config.ProfileStore;
import io.floci.cli.output.Ansi;
import io.floci.cli.output.Printer;
import picocli.CommandLine.*;
import java.io.IOException;
import java.util.List;
import java.util.concurrent.Callable;
@Command(
name = "profile",
description = "Manage Floci configuration profiles",
mixinStandardHelpOptions = true,
subcommands = {HelpCommand.class}
)
public class ConfigProfileCommand implements Callable<Integer> {
@Mixin
GlobalOptions global;
@Parameters(index = "0", description = "Action: list, show, create, delete", paramLabel = "list|show|create|delete")
String action;
@Parameters(index = "1", description = "Profile name (required for show, create, delete)", arity = "0..1", paramLabel = "<name>")
String name;
@Override
public Integer call() {
Printer printer = global.printer();
ProfileStore store = new ProfileStore();
return switch (action.toLowerCase()) {
case "list" -> listProfiles(printer, store);
case "show" -> showProfile(printer, store);
case "create" -> createProfile(printer, store);
case "delete" -> deleteProfile(printer, store);
default -> {
printer.error("Unknown action '" + action + "'. Use: list, show, create, delete");
yield 1;
}
};
}
private int listProfiles(Printer printer, ProfileStore store) {
try {
List<Profile> profiles = store.list();
if (profiles.isEmpty()) {
printer.println(Ansi.gray("No profiles found. Create one with: floci config profile create <name>"));
return 0;
}
printer.println(Ansi.bold("Profiles:"));
for (Profile p : profiles) {
printer.println(" " + p.name + Ansi.gray(" " + (p.endpoint != null ? p.endpoint : "")));
}
return 0;
} catch (IOException e) {
printer.error("Could not list profiles: " + e.getMessage());
return 1;
}
}
private int showProfile(Printer printer, ProfileStore store) {
if (name == null) { printer.error("Profile name required."); return 1; }
try {
var profile = store.get(name);
if (profile.isEmpty()) { printer.error("Profile '" + name + "' not found."); return 1; }
Profile p = profile.get();
printer.println(Ansi.bold("Profile: ") + p.name);
if (p.endpoint != null) printer.println(" endpoint: " + p.endpoint);
if (p.container != null) printer.println(" container: " + p.container);
if (p.image != null) printer.println(" image: " + p.image);
if (p.port != null) printer.println(" port: " + p.port);
if (p.persistDir != null) printer.println(" persistDir: " + p.persistDir);
if (p.services != null) printer.println(" services: " + p.services);
return 0;
} catch (IOException e) {
printer.error("Could not read profile: " + e.getMessage());
return 1;
}
}
private int createProfile(Printer printer, ProfileStore store) {
if (name == null) { printer.error("Profile name required."); return 1; }
try {
if (store.get(name).isPresent()) {
printer.error("Profile '" + name + "' already exists. Delete it first or edit " + store.profileFile(name));
return 1;
}
Profile p = new Profile(name);
store.save(p);
printer.println(Ansi.green("Created") + " profile '" + name + "' at " + store.profileFile(name));
printer.println(Ansi.gray("Edit the file to customize endpoint, container, image, etc."));
return 0;
} catch (IOException e) {
printer.error("Could not create profile: " + e.getMessage());
return 1;
}
}
private int deleteProfile(Printer printer, ProfileStore store) {
if (name == null) { printer.error("Profile name required."); return 1; }
try {
if (!store.delete(name)) {
printer.error("Profile '" + name + "' not found.");
return 1;
}
printer.println(Ansi.green("Deleted") + " profile '" + name + "'");
return 0;
} catch (IOException e) {
printer.error("Could not delete profile: " + e.getMessage());
return 1;
}
}
}
@@ -0,0 +1,70 @@
package io.floci.cli.commands.config;
import io.floci.cli.GlobalOptions;
import io.floci.cli.config.Profile;
import io.floci.cli.config.ProfileStore;
import io.floci.cli.output.Ansi;
import io.floci.cli.output.OutputFormat;
import io.floci.cli.output.Printer;
import picocli.CommandLine.*;
import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.Callable;
@Command(
name = "show",
description = "Show the active configuration",
mixinStandardHelpOptions = true
)
public class ConfigShowCommand implements Callable<Integer> {
@Mixin
GlobalOptions global;
@Override
public Integer call() {
Printer printer = global.printer();
ProfileStore store = new ProfileStore();
Profile active = new Profile(global.profile != null ? global.profile : "default");
active.endpoint = global.endpoint;
active.container = global.container;
active.output = global.output != null ? global.output.name() : "text";
if (global.profile != null) {
try {
Optional<Profile> loaded = store.get(global.profile);
if (loaded.isPresent()) {
active = loaded.get();
} else {
printer.warn("Profile '" + global.profile + "' not found. Using defaults.");
}
} catch (IOException e) {
printer.warn("Could not load profile: " + e.getMessage());
}
}
Map<String, Object> data = new LinkedHashMap<>();
data.put("profile", active.name);
data.put("endpoint", active.endpoint != null ? active.endpoint : global.endpoint);
data.put("container", active.container != null ? active.container : global.container);
data.put("output", active.output);
if (printer.format() != OutputFormat.text) {
printer.structured(data);
return 0;
}
printer.println(Ansi.bold("Active Configuration"));
printer.println("");
printer.println(" Profile: " + active.name);
printer.println(" Endpoint: " + (active.endpoint != null ? active.endpoint : global.endpoint));
printer.println(" Container: " + (active.container != null ? active.container : global.container));
printer.println(" Output: " + (active.output != null ? active.output : "text"));
return 0;
}
}
@@ -0,0 +1,94 @@
package io.floci.cli.commands.config;
import io.floci.cli.GlobalOptions;
import io.floci.cli.output.Ansi;
import io.floci.cli.output.Printer;
import picocli.CommandLine.*;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.regex.Pattern;
@Command(
name = "validate",
description = "Validate a docker-compose.yml file for Floci compatibility",
mixinStandardHelpOptions = true
)
public class ConfigValidateCommand implements Callable<Integer> {
@Mixin
GlobalOptions global;
@Option(names = {"--file", "-f"}, description = "Path to docker-compose file", paramLabel = "<path>")
String file;
@Override
public Integer call() {
Printer printer = global.printer();
Path composeFile = resolveComposeFile();
if (composeFile == null) {
printer.error("No docker-compose file found. Pass --file <path> or run in a directory with docker-compose.yml.");
return 1;
}
String content;
try {
content = Files.readString(composeFile);
} catch (IOException e) {
printer.error("Could not read " + composeFile + ": " + e.getMessage());
return 1;
}
printer.println(Ansi.bold("Validating") + " " + composeFile);
printer.println("");
List<String> issues = new ArrayList<>();
List<String> warnings = new ArrayList<>();
// Check for docker.sock mount
if (!content.contains("/var/run/docker.sock")) {
issues.add("Missing /var/run/docker.sock volume mount — required for Lambda, EC2, EKS, MSK, ECR, CodeBuild");
}
// Check port mapping
if (!Pattern.compile("4566\\s*:\\s*4566").matcher(content).find()) {
issues.add("Port mapping 4566:4566 not found — Floci listens on 4566 by default");
}
// Check for floci image
if (!content.contains("floci/floci") && !content.contains("ghcr.io/floci-io/floci")) {
warnings.add("Floci image reference not detected — ensure your service uses floci/floci or ghcr.io/floci-io/floci");
}
for (String issue : issues) {
printer.println(" " + Ansi.red("✗") + " " + issue);
}
for (String warn : warnings) {
printer.println(" " + Ansi.yellow("⚠") + " " + warn);
}
if (issues.isEmpty() && warnings.isEmpty()) {
printer.println(" " + Ansi.green("✓") + " Compose file looks good");
}
printer.println("");
if (!issues.isEmpty()) {
printer.println(issues.size() + " error(s) found.");
return 1;
}
return 0;
}
private Path resolveComposeFile() {
if (file != null) return Path.of(file);
for (String name : List.of("docker-compose.yml", "docker-compose.yaml", "compose.yml", "compose.yaml")) {
Path p = Path.of(name);
if (Files.exists(p)) return p;
}
return null;
}
}
@@ -0,0 +1,26 @@
package io.floci.cli.commands.snapshot;
import picocli.CommandLine;
import picocli.CommandLine.*;
@Command(
name = "snapshot",
description = "Manage Floci state snapshots",
mixinStandardHelpOptions = true,
subcommands = {
SnapshotSaveCommand.class,
SnapshotLoadCommand.class,
SnapshotListCommand.class,
SnapshotDeleteCommand.class,
SnapshotExportCommand.class,
SnapshotImportCommand.class,
HelpCommand.class
}
)
public class SnapshotCommand implements Runnable {
@Override
public void run() {
new CommandLine(this).usage(System.out);
}
}
@@ -0,0 +1,38 @@
package io.floci.cli.commands.snapshot;
import io.floci.cli.GlobalOptions;
import io.floci.cli.http.FlociException;
import io.floci.cli.http.FlociHttpClient;
import io.floci.cli.output.Ansi;
import io.floci.cli.output.Printer;
import picocli.CommandLine.*;
import java.util.concurrent.Callable;
@Command(
name = "delete",
description = "Delete a snapshot",
mixinStandardHelpOptions = true
)
public class SnapshotDeleteCommand implements Callable<Integer> {
@Mixin
GlobalOptions global;
@Parameters(index = "0", description = "Snapshot name", paramLabel = "<name>")
String name;
@Override
public Integer call() {
Printer printer = global.printer();
FlociHttpClient client = new FlociHttpClient(global.endpoint);
try {
client.deleteSnapshot(name);
printer.println(Ansi.green("Snapshot deleted:") + " " + name);
return 0;
} catch (FlociException e) {
printer.error("Failed to delete snapshot: " + e.getMessage());
return 1;
}
}
}
@@ -0,0 +1,33 @@
package io.floci.cli.commands.snapshot;
import io.floci.cli.GlobalOptions;
import io.floci.cli.output.Printer;
import picocli.CommandLine.*;
import java.util.concurrent.Callable;
@Command(
name = "export",
description = "Export a snapshot to a tarball file",
mixinStandardHelpOptions = true
)
public class SnapshotExportCommand implements Callable<Integer> {
@Mixin
GlobalOptions global;
@Parameters(index = "0", description = "Snapshot name", paramLabel = "<name>")
String name;
@Option(names = {"--file", "-f"}, description = "Destination file path", required = true, paramLabel = "<path>")
String outputFile;
@Override
public Integer call() {
Printer printer = global.printer();
// TODO: implement GET /_floci/snapshots/<name>/export streaming to file
printer.error("snapshot export requires floci-server >= 1.6.0\n" +
"See TODO.md for the required server-side API contract.");
return 1;
}
}
@@ -0,0 +1,33 @@
package io.floci.cli.commands.snapshot;
import io.floci.cli.GlobalOptions;
import io.floci.cli.output.Printer;
import picocli.CommandLine.*;
import java.util.concurrent.Callable;
@Command(
name = "import",
description = "Import a snapshot from a tarball file",
mixinStandardHelpOptions = true
)
public class SnapshotImportCommand implements Callable<Integer> {
@Mixin
GlobalOptions global;
@Option(names = {"--file", "-f"}, description = "Source tarball path", required = true, paramLabel = "<path>")
String inputFile;
@Option(names = {"--name"}, description = "Name for the imported snapshot", paramLabel = "<name>")
String name;
@Override
public Integer call() {
Printer printer = global.printer();
// TODO: implement POST /_floci/snapshots/import with multipart upload
printer.error("snapshot import requires floci-server >= 1.6.0\n" +
"See TODO.md for the required server-side API contract.");
return 1;
}
}
@@ -0,0 +1,50 @@
package io.floci.cli.commands.snapshot;
import io.floci.cli.GlobalOptions;
import io.floci.cli.http.FlociException;
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.concurrent.Callable;
@Command(
name = "list",
description = "List available snapshots",
mixinStandardHelpOptions = true
)
public class SnapshotListCommand implements Callable<Integer> {
@Mixin
GlobalOptions global;
@Override
public Integer call() {
Printer printer = global.printer();
FlociHttpClient client = new FlociHttpClient(global.endpoint);
try {
var node = client.listSnapshots();
if (printer.format() != OutputFormat.text) {
printer.structured(node);
return 0;
}
if (node.isArray() && node.size() == 0) {
printer.println(Ansi.gray("No snapshots found."));
return 0;
}
printer.println(Ansi.bold("Snapshots:"));
node.forEach(s -> printer.println(" " + s.asText()));
return 0;
} catch (FlociException e) {
if (e.getMessage().contains("404") || e.getMessage().contains("501")) {
printer.error("Snapshot API not available on this server version.\n" +
"See TODO.md for the required server-side API contract.");
} else {
printer.error("Failed to list snapshots: " + e.getMessage());
}
return 1;
}
}
}
@@ -0,0 +1,43 @@
package io.floci.cli.commands.snapshot;
import io.floci.cli.GlobalOptions;
import io.floci.cli.http.FlociException;
import io.floci.cli.http.FlociHttpClient;
import io.floci.cli.output.Ansi;
import io.floci.cli.output.Printer;
import picocli.CommandLine.*;
import java.util.concurrent.Callable;
@Command(
name = "load",
description = "Restore a saved snapshot",
mixinStandardHelpOptions = true
)
public class SnapshotLoadCommand implements Callable<Integer> {
@Mixin
GlobalOptions global;
@Parameters(index = "0", description = "Snapshot name", paramLabel = "<name>")
String name;
@Override
public Integer call() {
Printer printer = global.printer();
FlociHttpClient client = new FlociHttpClient(global.endpoint);
try {
client.loadSnapshot(name);
printer.println(Ansi.green("Snapshot loaded:") + " " + name);
return 0;
} catch (FlociException e) {
if (e.getMessage().contains("404") || e.getMessage().contains("501")) {
printer.error("Snapshot API not available on this server version.\n" +
"See TODO.md for the required server-side API contract.");
} else {
printer.error("Failed to load snapshot: " + e.getMessage());
}
return 1;
}
}
}
@@ -0,0 +1,46 @@
package io.floci.cli.commands.snapshot;
import io.floci.cli.GlobalOptions;
import io.floci.cli.http.FlociException;
import io.floci.cli.http.FlociHttpClient;
import io.floci.cli.output.Ansi;
import io.floci.cli.output.Printer;
import picocli.CommandLine.*;
import java.util.concurrent.Callable;
@Command(
name = "save",
description = "Save the current Floci state as a named snapshot",
mixinStandardHelpOptions = true
)
public class SnapshotSaveCommand implements Callable<Integer> {
@Mixin
GlobalOptions global;
@Parameters(index = "0", description = "Snapshot name", paramLabel = "<name>")
String name;
@Option(names = {"--message", "-m"}, description = "Optional description", paramLabel = "<text>")
String message;
@Override
public Integer call() {
Printer printer = global.printer();
FlociHttpClient client = new FlociHttpClient(global.endpoint);
try {
client.postSnapshot(name);
printer.println(Ansi.green("Snapshot saved:") + " " + name);
return 0;
} catch (FlociException e) {
if (e.getMessage().contains("404") || e.getMessage().contains("501")) {
printer.error("Snapshot API not available on this server version.\n" +
"See TODO.md for the required server-side API contract.");
} else {
printer.error("Failed to save snapshot: " + e.getMessage());
}
return 1;
}
}
}