fix: adding floci aws/az commands

This commit is contained in:
Hector Ventura committed 2026-05-15 18:08:45 -05:00
1 parent 77c2e75835
commit 11883f5b67
41 files changed
+2025 -113

No files matched your search

@@ -0,0 +1,80 @@
package io.floci.cli;
import io.floci.cli.docker.DockerClient;
import io.floci.cli.output.Ansi;
import io.floci.cli.output.OutputFormat;
import io.floci.cli.output.Printer;
import picocli.CommandLine.Option;
import java.net.URI;
public class AzGlobalOptions {
@Option(names = {"--endpoint"},
description = "Floci Azure server endpoint URL",
defaultValue = "${FLOCI_AZ_ENDPOINT:-http://localhost:4577}",
paramLabel = "<url>")
public String endpoint;
@Option(names = {"--container"},
description = "Floci Azure container name",
defaultValue = "${FLOCI_AZ_CONTAINER:-floci-az}",
paramLabel = "<name>")
public String container;
@Option(names = {"--profile"},
description = "Config profile from ~/.floci/profiles/",
paramLabel = "<name>")
public String profile;
@Option(names = {"--output", "-o"},
description = "Output format: text, json, yaml",
defaultValue = "text",
paramLabel = "text|json|yaml")
public OutputFormat output;
@Option(names = {"--quiet", "-q"}, description = "Suppress non-error output")
public boolean quiet;
@Option(names = {"--verbose", "-v"}, description = "Debug logging to stderr")
public boolean verbose;
@Option(names = {"--no-color"}, description = "Disable ANSI colors")
public boolean noColor;
public Printer printer() {
if (noColor || System.console() == null) {
Ansi.disable();
}
return new Printer(System.out, System.err, output, quiet);
}
public String resolvedEndpoint(DockerClient docker) {
try {
return docker.inspectContainer(container)
.map(info -> endpointFromPorts(info.ports(), endpoint))
.orElse(endpoint);
} catch (Exception e) {
return endpoint;
}
}
public String endpointFromPorts(String ports, String fallback) {
if (ports == null || ports.isBlank()) return fallback;
try {
int containerPort = URI.create(fallback).getPort();
if (containerPort == -1) containerPort = 4577;
for (String mapping : ports.trim().split("\\s+")) {
int arrow = mapping.indexOf("->");
if (arrow < 0) continue;
String hostPort = mapping.substring(0, arrow);
String rest = mapping.substring(arrow + 2);
String cPort = rest.contains("/") ? rest.substring(0, rest.indexOf('/')) : rest;
if (String.valueOf(containerPort).equals(cPort)) {
return "http://localhost:" + hostPort;
}
}
} catch (Exception ignored) {}
return fallback;
}
}
+40 -6
View File
@@ -1,21 +1,25 @@
package io.floci.cli;
import io.floci.cli.commands.*;
import io.floci.cli.commands.aws.AwsCommand;
import io.floci.cli.commands.az.AzCommand;
import io.floci.cli.commands.config.ConfigCommand;
import io.floci.cli.commands.snapshot.SnapshotCommand;
import io.floci.cli.config.GlobalConfigStore;
import io.floci.cli.output.Ansi;
import picocli.CommandLine;
import picocli.CommandLine.*;
@Command(
name = "floci",
description = "Manage your local Floci AWS emulator%n%n" +
" floci start — launch the container%n" +
description = "Manage your local Floci emulators%n%n" +
" floci start — launch the container (default: aws)%n" +
" floci stop — stop the container%n" +
" floci status — show health and version%n" +
" floci doctor — diagnose environment issues%n" +
" floci logs — stream container logs%n" +
" floci env — print AWS environment variables%n",
" floci env — print environment variables%n" +
" floci aws — explicit AWS emulator commands%n" +
" floci az — Azure emulator commands%n",
mixinStandardHelpOptions = true,
versionProvider = FlociCli.VersionProvider.class,
subcommands = {
@@ -32,6 +36,8 @@ import picocli.CommandLine.*;
ConfigCommand.class,
SnapshotCommand.class,
CompletionCommand.class,
AwsCommand.class,
AzCommand.class,
HelpCommand.class
}
)
@@ -56,17 +62,45 @@ public class FlociCli implements Runnable {
}
public static void main(String[] args) {
// Honor NO_COLOR and non-TTY environments
if (System.getenv("NO_COLOR") != null || System.console() == null) {
Ansi.disable();
}
// If no explicit product subcommand, route bare commands to the configured default.
// "floci az start" and "floci aws start" always win; only bare "floci start" is affected.
String[] effectiveArgs = args;
if (!isExplicitProduct(args)) {
String defaultProduct = new GlobalConfigStore().getDefaultProduct();
if ("az".equals(defaultProduct)) {
effectiveArgs = prepend("az", args);
}
}
int exitCode = new CommandLine(new FlociCli())
.setExecutionExceptionHandler(new ExceptionHandler())
.setCaseInsensitiveEnumValuesAllowed(true)
.execute(args);
.execute(effectiveArgs);
System.exit(exitCode);
}
// Returns true when routing should NOT apply: explicit product subgroup,
// or a product-independent command like "config" or "completion".
private static boolean isExplicitProduct(String[] args) {
for (String arg : args) {
if (arg.startsWith("-")) continue;
return "aws".equals(arg) || "az".equals(arg)
|| "config".equals(arg) || "completion".equals(arg) || "help".equals(arg);
}
return false;
}
private static String[] prepend(String token, String[] args) {
String[] result = new String[args.length + 1];
result[0] = token;
System.arraycopy(args, 0, result, 1, args.length);
return result;
}
@Override
public void run() {
new CommandLine(this).usage(System.out);
@@ -0,0 +1,22 @@
package io.floci.cli;
public record ProductProfile(
String name,
String defaultImage,
String defaultContainer,
int defaultPort,
String endpointEnvVar,
String containerEnvVar,
String persistPath,
String servicesEnvVar
) {
public static final ProductProfile AWS = new ProductProfile(
"aws", "floci/floci:latest", "floci", 4566,
"FLOCI_ENDPOINT", "FLOCI_CONTAINER", "/var/lib/floci", "FLOCI_SERVICES"
);
public static final ProductProfile AZ = new ProductProfile(
"az", "floci/floci-az:latest", "floci-az", 4577,
"FLOCI_AZ_ENDPOINT", "FLOCI_AZ_CONTAINER", "/app/data", "FLOCI_AZ_SERVICES"
);
}
@@ -43,7 +43,7 @@ public class DoctorCommand implements Callable<Integer> {
@Option(names = {"--fix"}, description = "Attempt to auto-fix fixable issues")
boolean fix;
private static final List<Check> ALL_CHECKS = List.of(
public static final List<Check> DOCKER_CHECKS = List.of(
new DockerInstalledCheck(),
new DockerDaemonCheck(),
new DockerSocketCheck(),
@@ -52,11 +52,26 @@ public class DoctorCommand implements Callable<Integer> {
new ImagePresentCheck(),
new ImageVersionCheck(),
new ContainerRunningCheck(),
new EndpointReachableCheck(),
new EndpointReachableCheck()
);
public static final List<Check> AWS_COMPANION_CHECKS = List.of(
new AwsCliEndpointCheck(),
new AwsCliS3PathStyleCheck()
);
private final List<Check> allChecks;
public DoctorCommand() {
this(AWS_COMPANION_CHECKS);
}
public DoctorCommand(List<Check> companionChecks) {
List<Check> checks = new ArrayList<>(DOCKER_CHECKS);
checks.addAll(companionChecks);
this.allChecks = List.copyOf(checks);
}
@Override
public Integer call() {
Printer printer = global.printer();
@@ -70,7 +85,7 @@ public class DoctorCommand implements Callable<Integer> {
printer.println("");
}
for (Check check : ALL_CHECKS) {
for (Check check : allChecks) {
CheckResult result = check.run(effectiveEndpoint, global.container);
if (checkName != null && !result.name().equals(checkName)) continue;
results.add(result);
@@ -105,7 +120,7 @@ public class DoctorCommand implements Callable<Integer> {
return fails > 0 ? 1 : 0;
}
private void printResult(Printer printer, CheckResult r) {
public static void printResult(Printer printer, CheckResult r) {
String icon = switch (r.status()) {
case ok -> Ansi.green("✓");
case warn -> Ansi.yellow("⚠");
@@ -1,6 +1,7 @@
package io.floci.cli.commands;
import io.floci.cli.GlobalOptions;
import io.floci.cli.docker.DockerClient;
import io.floci.cli.output.Ansi;
import io.floci.cli.output.OutputFormat;
import io.floci.cli.output.Printer;
@@ -42,7 +43,8 @@ public class EnvCommand implements Callable<Integer> {
@Override
public Integer call() {
Printer printer = global.printer();
int port = extractPort(global.endpoint);
String effectiveEndpoint = global.resolvedEndpoint(new DockerClient());
int port = extractPort(effectiveEndpoint);
String endpointUrl = "http://" + host + ":" + port;
Map<String, String> vars = new LinkedHashMap<>();
@@ -0,0 +1,41 @@
package io.floci.cli.commands.aws;
import io.floci.cli.commands.*;
import io.floci.cli.commands.config.ConfigCommand;
import io.floci.cli.commands.snapshot.SnapshotCommand;
import picocli.CommandLine;
import picocli.CommandLine.*;
@Command(
name = "aws",
description = "Manage the Floci AWS emulator%n%n" +
" floci aws start — launch the container%n" +
" floci aws stop — stop the container%n" +
" floci aws status — show health and version%n" +
" floci aws doctor — diagnose environment issues%n" +
" floci aws env — print AWS environment variables%n",
mixinStandardHelpOptions = true,
subcommands = {
StartCommand.class,
StopCommand.class,
RestartCommand.class,
StatusCommand.class,
LogsCommand.class,
WaitCommand.class,
VersionCommand.class,
ServicesCommand.class,
DoctorCommand.class,
EnvCommand.class,
ConfigCommand.class,
SnapshotCommand.class,
CompletionCommand.class,
HelpCommand.class
}
)
public class AwsCommand implements Runnable {
@Override
public void run() {
new CommandLine(this).usage(System.out);
}
}
@@ -0,0 +1,41 @@
package io.floci.cli.commands.az;
import io.floci.cli.commands.CompletionCommand;
import io.floci.cli.commands.az.config.AzConfigCommand;
import io.floci.cli.commands.az.snapshot.AzSnapshotCommand;
import picocli.CommandLine;
import picocli.CommandLine.*;
@Command(
name = "az",
description = "Manage the Floci Azure emulator (floci-az)%n%n" +
" floci az start — launch the container%n" +
" floci az stop — stop the container%n" +
" floci az status — show health and version%n" +
" floci az doctor — diagnose environment issues%n" +
" floci az env — print Azure environment variables%n",
mixinStandardHelpOptions = true,
subcommands = {
AzStartCommand.class,
AzStopCommand.class,
AzRestartCommand.class,
AzStatusCommand.class,
AzLogsCommand.class,
AzWaitCommand.class,
AzVersionCommand.class,
AzServicesCommand.class,
AzDoctorCommand.class,
AzEnvCommand.class,
AzConfigCommand.class,
AzSnapshotCommand.class,
CompletionCommand.class,
HelpCommand.class
}
)
public class AzCommand implements Runnable {
@Override
public void run() {
new CommandLine(this).usage(System.out);
}
}
@@ -0,0 +1,116 @@
package io.floci.cli.commands.az;
import io.floci.cli.AzGlobalOptions;
import io.floci.cli.commands.DoctorCommand;
import io.floci.cli.doctor.Check;
import io.floci.cli.doctor.CheckResult;
import io.floci.cli.doctor.CheckStatus;
import io.floci.cli.docker.DockerClient;
import io.floci.cli.doctor.checks.AzCliConnectionStringCheck;
import io.floci.cli.doctor.checks.AzCliInstalledCheck;
import io.floci.cli.doctor.checks.ContainerRunningCheck;
import io.floci.cli.doctor.checks.DockerDaemonCheck;
import io.floci.cli.doctor.checks.DockerInstalledCheck;
import io.floci.cli.doctor.checks.DockerSocketCheck;
import io.floci.cli.doctor.checks.DockerVersionCheck;
import io.floci.cli.doctor.checks.EndpointReachableCheck;
import io.floci.cli.doctor.checks.ImagePresentCheck;
import io.floci.cli.doctor.checks.ImageVersionCheck;
import io.floci.cli.doctor.checks.PortAvailableCheck;
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 Azure",
mixinStandardHelpOptions = true
)
public class AzDoctorCommand implements Callable<Integer> {
@Mixin
AzGlobalOptions 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;
public static final List<Check> AZ_COMPANION_CHECKS = List.of(
new AzCliInstalledCheck(),
new AzCliConnectionStringCheck()
);
private static final List<Check> ALL_CHECKS;
static {
List<Check> checks = new ArrayList<>();
checks.add(new DockerInstalledCheck());
checks.add(new DockerDaemonCheck());
checks.add(new DockerSocketCheck());
checks.add(new DockerVersionCheck());
checks.add(new PortAvailableCheck());
checks.add(new ImagePresentCheck("floci/floci-az"));
checks.add(new ImageVersionCheck("floci/floci-az"));
checks.add(new ContainerRunningCheck());
checks.add(new EndpointReachableCheck());
checks.addAll(AZ_COMPANION_CHECKS);
ALL_CHECKS = List.copyOf(checks);
}
@Override
public Integer call() {
Printer printer = global.printer();
List<CheckResult> results = new ArrayList<>();
String effectiveEndpoint = global.resolvedEndpoint(new DockerClient());
boolean textMode = printer.format() == OutputFormat.text;
if (textMode) {
printer.println(Ansi.bold("Floci Azure Doctor") + " — checking your environment");
printer.println("");
}
for (Check check : ALL_CHECKS) {
CheckResult result = check.run(effectiveEndpoint, global.container);
if (checkName != null && !result.name().equals(checkName)) continue;
results.add(result);
if (textMode) DoctorCommand.printResult(printer, result);
}
if (!textMode) {
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;
}
}
@@ -0,0 +1,161 @@
package io.floci.cli.commands.az;
import io.floci.cli.AzGlobalOptions;
import io.floci.cli.docker.DockerClient;
import io.floci.cli.doctor.checks.AzCliConnectionStringCheck;
import io.floci.cli.output.Ansi;
import io.floci.cli.output.OutputFormat;
import io.floci.cli.output.Printer;
import picocli.CommandLine.*;
import java.net.URI;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Callable;
@Command(
name = "env",
description = "Print Azure environment variables to connect to Floci Azure",
mixinStandardHelpOptions = true
)
public class AzEnvCommand implements Callable<Integer> {
private static final String DEV_ACCOUNT = "devstoreaccount1";
private static final String DEV_KEY =
"Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMh0==";
private static final Set<String> ALL_SERVICES =
Set.of("blob", "queue", "table", "functions", "app-config", "key-vault");
@Mixin
AzGlobalOptions global;
@Option(names = {"--format"},
description = "Output mode: connection-string, sdk-vars (default: connection-string)",
defaultValue = "connection-string",
paramLabel = "connection-string|sdk-vars")
String format;
@Option(names = {"--service"},
description = "Comma-separated services for sdk-vars mode: blob,queue,table,functions,app-config,key-vault",
paramLabel = "<csv>")
String serviceFilter;
@Option(names = {"--account"},
description = "Storage account name (default: devstoreaccount1)",
defaultValue = "${FLOCI_AZ_ACCOUNT:-devstoreaccount1}",
paramLabel = "<name>")
String account;
@Option(names = {"--host"},
description = "Hostname for endpoint URLs (default: localhost.floci.io)",
defaultValue = "${FLOCI_AZ_HOST:-localhost.floci.io}",
paramLabel = "<host>")
String host;
@Option(names = {"--shell"},
description = "Shell format: bash, fish, powershell (default: bash)",
defaultValue = "bash",
paramLabel = "bash|fish|powershell")
String shell;
@Override
public Integer call() {
Printer printer = global.printer();
String effectiveEndpoint = global.resolvedEndpoint(new DockerClient());
int port = extractPort(effectiveEndpoint);
boolean sdkVarsMode = "sdk-vars".equals(format) || serviceFilter != null;
List<String> requestedServices = resolveServices();
if (printer.format() != OutputFormat.text) {
Map<String, Object> out = new LinkedHashMap<>();
if (!sdkVarsMode) {
out.put("AZURE_STORAGE_CONNECTION_STRING",
AzCliConnectionStringCheck.buildConnectionString(account, host, port));
} else {
out.put("AZURE_STORAGE_ACCOUNT", account);
out.put("AZURE_STORAGE_KEY", DEV_KEY);
for (String svc : requestedServices) {
out.put(envVarName(svc), buildEndpointUrl(svc, host, port, account));
}
}
printer.structured(out);
return 0;
}
if (!sdkVarsMode) {
String connStr = AzCliConnectionStringCheck.buildConnectionString(account, host, port);
printer.println(formatExport("AZURE_STORAGE_CONNECTION_STRING", connStr));
printer.println("");
printer.println(Ansi.gray("# Run: eval $(floci az env)"));
} else {
printer.println(formatExport("AZURE_STORAGE_ACCOUNT", account));
printer.println(formatExport("AZURE_STORAGE_KEY", DEV_KEY));
for (String svc : requestedServices) {
printer.println(formatExport(envVarName(svc), buildEndpointUrl(svc, host, port, account)));
}
printer.println("");
printer.println(Ansi.gray("# Run: eval $(floci az env --format sdk-vars)"));
}
return 0;
}
private List<String> resolveServices() {
if (serviceFilter != null && !serviceFilter.isBlank()) {
List<String> result = new ArrayList<>();
for (String s : serviceFilter.split(",")) {
String svc = s.trim().toLowerCase();
if (ALL_SERVICES.contains(svc)) result.add(svc);
}
return result;
}
return List.of("blob", "queue", "table", "functions", "app-config", "key-vault");
}
private String envVarName(String service) {
return switch (service) {
case "blob" -> "AZURE_STORAGE_BLOB_ENDPOINT";
case "queue" -> "AZURE_STORAGE_QUEUE_ENDPOINT";
case "table" -> "AZURE_STORAGE_TABLE_ENDPOINT";
case "functions" -> "AZURE_FUNCTIONS_ENDPOINT";
case "app-config" -> "AZURE_APP_CONFIGURATION_ENDPOINT";
case "key-vault" -> "AZURE_KEY_VAULT_ENDPOINT";
default -> "AZURE_" + service.toUpperCase().replace('-', '_') + "_ENDPOINT";
};
}
private String buildEndpointUrl(String service, String host, int port, String accountName) {
String base = "http://" + host + ":" + port + "/" + accountName;
return switch (service) {
case "blob" -> base;
case "queue" -> base + "-queue";
case "table" -> base + "-table";
case "functions" -> base + "-functions";
case "app-config" -> base + "-appconfig";
case "key-vault" -> base + "-keyvault";
default -> base + "-" + service;
};
}
private String formatExport(String key, String value) {
return switch (shell.toLowerCase()) {
case "fish" -> "set -x " + key + " \"" + value + "\"";
case "powershell", "ps1" -> "$env:" + key + " = \"" + value + "\"";
default -> "export " + key + "=" + value;
};
}
private int extractPort(String endpoint) {
try {
int p = URI.create(endpoint).getPort();
return p == -1 ? 4577 : p;
} catch (Exception e) {
return 4577;
}
}
}
@@ -0,0 +1,54 @@
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.Printer;
import picocli.CommandLine.*;
import java.util.concurrent.Callable;
@Command(
name = "logs",
description = "Fetch logs from the Floci Azure container",
mixinStandardHelpOptions = true
)
public class AzLogsCommand implements Callable<Integer> {
@Mixin
AzGlobalOptions 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;
@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;
}
} catch (DockerException e) {
printer.error("Failed to inspect container: " + e.getMessage());
return 1;
}
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,40 @@
package io.floci.cli.commands.az;
import io.floci.cli.AzGlobalOptions;
import io.floci.cli.output.Printer;
import picocli.CommandLine.*;
import java.util.concurrent.Callable;
@Command(
name = "restart",
description = "Stop and restart the Floci Azure container",
mixinStandardHelpOptions = true
)
public class AzRestartCommand implements Callable<Integer> {
@Mixin
AzGlobalOptions global;
@Override
public Integer call() {
Printer printer = global.printer();
AzStopCommand stop = new AzStopCommand();
stop.global = global;
stop.remove = false;
stop.timeout = 10;
int stopResult = stop.call();
if (stopResult != 0) return stopResult;
try { Thread.sleep(1000); } catch (InterruptedException e) { Thread.currentThread().interrupt(); }
AzStartCommand start = new AzStartCommand();
start.global = global;
start.port = 4577;
start.pull = "missing";
start.image = "floci/floci-az:latest";
start.detach = false;
return start.call();
}
}
@@ -0,0 +1,55 @@
package io.floci.cli.commands.az;
import io.floci.cli.AzGlobalOptions;
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 Azure instance",
mixinStandardHelpOptions = true
)
public class AzServicesCommand implements Callable<Integer> {
@Mixin
AzGlobalOptions global;
@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 Azure at " + global.endpoint + ".\nIs Floci Azure running? Try 'floci az start'.");
return 1;
}
if (printer.format() != OutputFormat.text) {
printer.structured(Map.of("services", services, "count", services.size()));
return 0;
}
printer.println(Ansi.bold("Floci Azure 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,110 @@
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.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;
@Command(
name = "start",
description = "Start the Floci Azure emulator container",
mixinStandardHelpOptions = true
)
public class AzStartCommand implements Callable<Integer> {
@Mixin
AzGlobalOptions global;
@Option(names = {"--port"}, description = "Host port to bind (default: 4577)", defaultValue = "4577", 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-az:latest)", defaultValue = "floci/floci-az: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();
if (!DockerClient.isInstalled()) {
printer.error("docker binary not found in PATH.\nInstall Docker Desktop from https://docs.docker.com/get-docker/");
return 1;
}
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 az stop' first or pass --container <name> to use a different name.");
return 1;
}
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;
}
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 az start --pull never' to skip pulling.");
return 1;
}
List<String> args = new ArrayList<>();
args.addAll(List.of("-d", "--name", global.container));
args.addAll(List.of("-p", port + ":4577"));
args.addAll(List.of("-v", "/var/run/docker.sock:/var/run/docker.sock"));
if (persistDir != null) {
args.addAll(List.of("-v", persistDir + ":/app/data"));
}
if (services != null && !services.isBlank()) {
args.addAll(List.of("-e", "FLOCI_AZ_SERVICES=" + services));
}
args.add(image);
try {
printer.println("Starting " + Ansi.gold("Floci Azure") + " 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 az wait' to poll for readiness."));
return 0;
}
global.endpoint = "http://localhost:" + port;
printer.println(Ansi.gray("Waiting for Floci Azure to be ready..."));
AzWaitCommand wait = new AzWaitCommand();
wait.global = global;
wait.timeout = "30s";
return wait.call();
}
}
@@ -0,0 +1,98 @@
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.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 Azure container and server status",
mixinStandardHelpOptions = true
)
public class AzStatusCommand implements Callable<Integer> {
@Mixin
AzGlobalOptions global;
@Override
public Integer call() {
Printer printer = global.printer();
DockerClient docker = new DockerClient();
String containerState = "not found";
String containerImage = "";
String containerPorts = "";
String effectiveEndpoint = global.endpoint;
try {
Optional<DockerClient.ContainerInfo> info = docker.inspectContainer(global.container);
if (info.isPresent()) {
containerState = info.get().state();
containerImage = info.get().image();
containerPorts = info.get().ports();
effectiveEndpoint = global.endpointFromPorts(containerPorts, global.endpoint);
}
} catch (DockerException e) {
containerState = "error: " + e.getMessage();
}
String serverVersion = "unavailable";
String serverEdition = "";
boolean reachable = false;
FlociHttpClient client = new FlociHttpClient(effectiveEndpoint);
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", effectiveEndpoint);
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 Azure 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: " + effectiveEndpoint);
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 az start' to launch Floci Azure."));
}
return 0;
}
}
@@ -0,0 +1,73 @@
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;
@Command(
name = "stop",
description = "Stop the Floci Azure container",
mixinStandardHelpOptions = true
)
public class AzStopCommand implements Callable<Integer> {
@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;
}
}
@@ -0,0 +1,72 @@
package io.floci.cli.commands.az;
import io.floci.cli.AzGlobalOptions;
import io.floci.cli.commands.VersionCommand;
import io.floci.cli.docker.DockerClient;
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 Azure server version, and image digest",
mixinStandardHelpOptions = true
)
public class AzVersionCommand implements Callable<Integer> {
@Mixin
AzGlobalOptions global;
@Override
public Integer call() {
Printer printer = global.printer();
String serverVersion = null;
String serverEdition = null;
String imageDigest = null;
DockerClient docker = new DockerClient();
String effectiveEndpoint = global.resolvedEndpoint(docker);
FlociHttpClient client = new FlociHttpClient(effectiveEndpoint);
try {
var info = client.info();
serverVersion = info.version();
serverEdition = info.edition();
} catch (Exception ignored) {}
try {
imageDigest = docker.imageDigest("floci/floci-az").orElse(null);
} catch (Exception ignored) {}
Map<String, Object> data = new LinkedHashMap<>();
data.put("cli", VersionCommand.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(VersionCommand.CLI_VERSION));
if (serverVersion != null) {
printer.println("Server: " + serverVersion + (serverEdition != null ? " (" + serverEdition + ")" : ""));
} else {
printer.println("Server: " + Ansi.gray("not reachable at " + effectiveEndpoint));
}
if (imageDigest != null) {
printer.println("Image: " + imageDigest);
}
return 0;
}
}
@@ -0,0 +1,73 @@
package io.floci.cli.commands.az;
import io.floci.cli.AzGlobalOptions;
import io.floci.cli.commands.WaitCommand;
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.time.Duration;
import java.time.Instant;
import java.util.Map;
import java.util.concurrent.Callable;
@Command(
name = "wait",
description = "Wait until Floci Azure is ready to accept requests",
mixinStandardHelpOptions = true
)
public class AzWaitCommand implements Callable<Integer> {
@Mixin
AzGlobalOptions 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 = WaitCommand.parseDuration(timeout);
String effectiveEndpoint = global.resolvedEndpoint(new io.floci.cli.docker.DockerClient());
FlociHttpClient client = new FlociHttpClient(effectiveEndpoint);
Instant deadline = Instant.now().plusMillis(timeoutMillis);
while (Instant.now().isBefore(deadline)) {
if (isReady(client, service)) {
if (printer.format() != OutputFormat.text) {
printer.structured(Map.of("ready", true, "endpoint", effectiveEndpoint));
} else {
printer.println(Ansi.green("Floci Azure is ready") + " (" + effectiveEndpoint + ")");
}
return 0;
}
long remaining = Duration.between(Instant.now(), deadline).toSeconds();
printer.print("\r" + Ansi.gray("Waiting... (" + remaining + "s remaining)") + " ");
try { Thread.sleep(500); } catch (InterruptedException e) {
Thread.currentThread().interrupt();
break;
}
}
printer.error("Timed out waiting for Floci Azure after " + timeout + ".\nIs the container running? Try 'floci az 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;
}
}
}
@@ -0,0 +1,23 @@
package io.floci.cli.commands.az.config;
import picocli.CommandLine;
import picocli.CommandLine.*;
@Command(
name = "config",
description = "Manage Floci Azure configuration",
mixinStandardHelpOptions = true,
subcommands = {
AzConfigShowCommand.class,
AzConfigValidateCommand.class,
AzConfigProfileCommand.class,
HelpCommand.class
}
)
public class AzConfigCommand implements Runnable {
@Override
public void run() {
new CommandLine(this).usage(System.out);
}
}
@@ -0,0 +1,115 @@
package io.floci.cli.commands.az.config;
import io.floci.cli.AzGlobalOptions;
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 Azure configuration profiles",
mixinStandardHelpOptions = true,
subcommands = {HelpCommand.class}
)
public class AzConfigProfileCommand implements Callable<Integer> {
@Mixin
AzGlobalOptions 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 az 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.az.config;
import io.floci.cli.AzGlobalOptions;
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 Floci Azure configuration",
mixinStandardHelpOptions = true
)
public class AzConfigShowCommand implements Callable<Integer> {
@Mixin
AzGlobalOptions 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 (Floci Azure)"));
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,91 @@
package io.floci.cli.commands.az.config;
import io.floci.cli.AzGlobalOptions;
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 Azure compatibility",
mixinStandardHelpOptions = true
)
public class AzConfigValidateCommand implements Callable<Integer> {
@Mixin
AzGlobalOptions 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<>();
if (!content.contains("/var/run/docker.sock")) {
warnings.add("Missing /var/run/docker.sock volume mount — required for Azure Functions");
}
if (!Pattern.compile("4577\\s*:\\s*4577").matcher(content).find()) {
issues.add("Port mapping 4577:4577 not found — Floci Azure listens on 4577 by default");
}
if (!content.contains("floci/floci-az") && !content.contains("ghcr.io/floci-io/floci-az")) {
warnings.add("Floci Azure image reference not detected — ensure your service uses floci/floci-az");
}
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.az.snapshot;
import picocli.CommandLine;
import picocli.CommandLine.*;
@Command(
name = "snapshot",
description = "Manage Floci Azure state snapshots (coming soon)",
mixinStandardHelpOptions = true,
subcommands = {
AzSnapshotSaveCommand.class,
AzSnapshotLoadCommand.class,
AzSnapshotListCommand.class,
AzSnapshotDeleteCommand.class,
AzSnapshotExportCommand.class,
AzSnapshotImportCommand.class,
HelpCommand.class
}
)
public class AzSnapshotCommand implements Runnable {
@Override
public void run() {
new CommandLine(this).usage(System.out);
}
}
@@ -0,0 +1,28 @@
package io.floci.cli.commands.az.snapshot;
import io.floci.cli.AzGlobalOptions;
import io.floci.cli.output.Ansi;
import picocli.CommandLine.*;
import java.util.concurrent.Callable;
@Command(
name = "delete",
description = "Delete a Floci Azure snapshot",
mixinStandardHelpOptions = true
)
public class AzSnapshotDeleteCommand implements Callable<Integer> {
@Mixin
AzGlobalOptions global;
@Parameters(index = "0", description = "Snapshot name", paramLabel = "<name>")
String name;
@Override
public Integer call() {
global.printer().println(Ansi.yellow("Snapshots are not yet available for Floci Azure.") +
"\nTrack progress: https://github.com/floci-io/floci-az/issues");
return 0;
}
}
@@ -0,0 +1,31 @@
package io.floci.cli.commands.az.snapshot;
import io.floci.cli.AzGlobalOptions;
import io.floci.cli.output.Ansi;
import picocli.CommandLine.*;
import java.util.concurrent.Callable;
@Command(
name = "export",
description = "Export a Floci Azure snapshot to a tarball file",
mixinStandardHelpOptions = true
)
public class AzSnapshotExportCommand implements Callable<Integer> {
@Mixin
AzGlobalOptions 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() {
global.printer().println(Ansi.yellow("Snapshots are not yet available for Floci Azure.") +
"\nTrack progress: https://github.com/floci-io/floci-az/issues");
return 0;
}
}
@@ -0,0 +1,31 @@
package io.floci.cli.commands.az.snapshot;
import io.floci.cli.AzGlobalOptions;
import io.floci.cli.output.Ansi;
import picocli.CommandLine.*;
import java.util.concurrent.Callable;
@Command(
name = "import",
description = "Import a Floci Azure snapshot from a tarball file",
mixinStandardHelpOptions = true
)
public class AzSnapshotImportCommand implements Callable<Integer> {
@Mixin
AzGlobalOptions 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() {
global.printer().println(Ansi.yellow("Snapshots are not yet available for Floci Azure.") +
"\nTrack progress: https://github.com/floci-io/floci-az/issues");
return 0;
}
}
@@ -0,0 +1,34 @@
package io.floci.cli.commands.az.snapshot;
import io.floci.cli.AzGlobalOptions;
import io.floci.cli.output.Ansi;
import io.floci.cli.output.OutputFormat;
import io.floci.cli.output.Printer;
import picocli.CommandLine.*;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;
@Command(
name = "list",
description = "List available Floci Azure snapshots",
mixinStandardHelpOptions = true
)
public class AzSnapshotListCommand implements Callable<Integer> {
@Mixin
AzGlobalOptions global;
@Override
public Integer call() {
Printer printer = global.printer();
if (printer.format() != OutputFormat.text) {
printer.structured(Map.of("snapshots", List.of(), "note", "not yet available"));
return 0;
}
printer.println(Ansi.gray("No snapshots found.") +
" (Snapshot support for Floci Azure is coming — https://github.com/floci-io/floci-az/issues)");
return 0;
}
}
@@ -0,0 +1,28 @@
package io.floci.cli.commands.az.snapshot;
import io.floci.cli.AzGlobalOptions;
import io.floci.cli.output.Ansi;
import picocli.CommandLine.*;
import java.util.concurrent.Callable;
@Command(
name = "load",
description = "Restore a saved Floci Azure snapshot",
mixinStandardHelpOptions = true
)
public class AzSnapshotLoadCommand implements Callable<Integer> {
@Mixin
AzGlobalOptions global;
@Parameters(index = "0", description = "Snapshot name", paramLabel = "<name>")
String name;
@Override
public Integer call() {
global.printer().println(Ansi.yellow("Snapshots are not yet available for Floci Azure.") +
"\nTrack progress: https://github.com/floci-io/floci-az/issues");
return 0;
}
}
@@ -0,0 +1,32 @@
package io.floci.cli.commands.az.snapshot;
import io.floci.cli.AzGlobalOptions;
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 Azure state as a named snapshot",
mixinStandardHelpOptions = true
)
public class AzSnapshotSaveCommand implements Callable<Integer> {
@Mixin
AzGlobalOptions 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() {
global.printer().println(Ansi.yellow("Snapshots are not yet available for Floci Azure.") +
"\nTrack progress: https://github.com/floci-io/floci-az/issues");
return 0;
}
}
@@ -11,6 +11,7 @@ import picocli.CommandLine.*;
ConfigShowCommand.class,
ConfigValidateCommand.class,
ConfigProfileCommand.class,
ConfigDefaultProductCommand.class,
HelpCommand.class
}
)
@@ -0,0 +1,44 @@
package io.floci.cli.commands.config;
import io.floci.cli.GlobalOptions;
import io.floci.cli.config.GlobalConfigStore;
import io.floci.cli.output.Ansi;
import io.floci.cli.output.Printer;
import picocli.CommandLine.*;
import java.io.IOException;
import java.util.concurrent.Callable;
@Command(
name = "default-product",
description = "Set the default product for bare commands like 'floci start'",
mixinStandardHelpOptions = true
)
public class ConfigDefaultProductCommand implements Callable<Integer> {
@Mixin
GlobalOptions global;
@Parameters(index = "0", description = "Product to use by default: aws, az", paramLabel = "aws|az")
String product;
@Override
public Integer call() {
Printer printer = global.printer();
if (!"aws".equals(product) && !"az".equals(product)) {
printer.error("Unknown product '" + product + "'. Use: aws, az");
return 1;
}
GlobalConfigStore store = new GlobalConfigStore();
try {
store.setDefaultProduct(product);
printer.println(Ansi.green("Default product set to: ") + Ansi.bold(product));
printer.println(Ansi.gray("'floci start' will now run: floci " + product + " start"));
printer.println(Ansi.gray("Config saved to: " + store.configFilePath()));
return 0;
} catch (IOException e) {
printer.error("Could not save config: " + e.getMessage());
return 1;
}
}
}
@@ -0,0 +1,50 @@
package io.floci.cli.config;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
public class GlobalConfigStore {
private static final ObjectMapper YAML = new ObjectMapper(new YAMLFactory());
private final Path configFile;
public GlobalConfigStore() {
this(Path.of(System.getProperty("user.home"), ".floci", "config.yaml"));
}
public GlobalConfigStore(Path configFile) {
this.configFile = configFile;
}
public String getDefaultProduct() {
if (!Files.exists(configFile)) return "aws";
try {
GlobalConfig config = YAML.readValue(configFile.toFile(), GlobalConfig.class);
return "az".equals(config.defaultProduct) ? "az" : "aws";
} catch (IOException e) {
return "aws";
}
}
public void setDefaultProduct(String product) throws IOException {
Files.createDirectories(configFile.getParent());
GlobalConfig config = new GlobalConfig();
config.defaultProduct = product;
YAML.writeValue(configFile.toFile(), config);
}
public Path configFilePath() {
return configFile;
}
public static class GlobalConfig {
@JsonProperty("default-product")
public String defaultProduct = "aws";
}
}
@@ -0,0 +1,59 @@
package io.floci.cli.doctor.checks;
import io.floci.cli.doctor.Check;
import io.floci.cli.doctor.CheckResult;
import java.net.URI;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class AzCliConnectionStringCheck implements Check {
private static final Pattern ENDPOINT_PORT_PATTERN =
Pattern.compile("BlobEndpoint=https?://[^:]+:(\\d+)/", Pattern.CASE_INSENSITIVE);
@Override
public CheckResult run(String endpoint, String container) {
String connStr = System.getenv("AZURE_STORAGE_CONNECTION_STRING");
int effectivePort = extractPort(endpoint);
if (connStr != null && !connStr.isBlank()) {
Matcher m = ENDPOINT_PORT_PATTERN.matcher(connStr);
if (m.find()) {
int connPort = Integer.parseInt(m.group(1));
if (effectivePort != -1 && connPort != effectivePort) {
String corrected = connStr.replaceAll(":(\\d+)/", ":" + effectivePort + "/");
return CheckResult.warn("az.cli.connection-string",
"AZURE_STORAGE_CONNECTION_STRING port mismatch — floci-az is on port " + effectivePort,
"export AZURE_STORAGE_CONNECTION_STRING=\"" + corrected + "\"");
}
}
return CheckResult.ok("az.cli.connection-string", "AZURE_STORAGE_CONNECTION_STRING is set");
}
int port = effectivePort != -1 ? effectivePort : 4577;
String suggested = buildConnectionString("devstoreaccount1", "localhost.floci.io", port);
return CheckResult.warn("az.cli.connection-string",
"AZURE_STORAGE_CONNECTION_STRING is not set",
"export AZURE_STORAGE_CONNECTION_STRING=\"" + suggested + "\"");
}
private int extractPort(String url) {
try {
int port = URI.create(url).getPort();
return port == -1 ? 4577 : port;
} catch (Exception e) {
return -1;
}
}
public static String buildConnectionString(String account, String host, int port) {
String base = "http://" + host + ":" + port + "/" + account;
return "DefaultEndpointsProtocol=http" +
";AccountName=" + account +
";AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMh0==" +
";BlobEndpoint=" + base +
";QueueEndpoint=" + base + "-queue" +
";TableEndpoint=" + base + "-table;";
}
}
@@ -0,0 +1,22 @@
package io.floci.cli.doctor.checks;
import io.floci.cli.doctor.Check;
import io.floci.cli.doctor.CheckResult;
public class AzCliInstalledCheck implements Check {
@Override
public CheckResult run(String endpoint, String container) {
try {
Process p = new ProcessBuilder("az", "--version").start();
if (p.waitFor() == 0) {
return CheckResult.ok("az.cli.installed", "az CLI found");
}
return CheckResult.warn("az.cli.installed", "az CLI not found in PATH",
"Install from https://learn.microsoft.com/en-us/cli/azure/install-azure-cli");
} catch (Exception e) {
return CheckResult.warn("az.cli.installed", "az CLI not found in PATH",
"Install from https://learn.microsoft.com/en-us/cli/azure/install-azure-cli");
}
}
}
@@ -7,17 +7,25 @@ import io.floci.cli.doctor.CheckResult;
public class ImagePresentCheck implements Check {
private static final String IMAGE = "floci/floci";
private final String image;
public ImagePresentCheck() {
this("floci/floci");
}
public ImagePresentCheck(String image) {
this.image = image;
}
@Override
public CheckResult run(String endpoint, String container) {
try {
DockerClient docker = new DockerClient();
if (docker.isImagePresent(IMAGE)) {
return CheckResult.ok("image.present", IMAGE + " image present locally");
if (docker.isImagePresent(image)) {
return CheckResult.ok("image.present", image + " image present locally");
}
return CheckResult.fail("image.present",
IMAGE + " not pulled locally",
image + " not pulled locally",
"floci start --pull always");
} catch (DockerException e) {
return CheckResult.warn("image.present", "Could not check image presence: " + e.getMessage(), null);
@@ -7,19 +7,27 @@ import io.floci.cli.doctor.CheckResult;
public class ImageVersionCheck implements Check {
private static final String IMAGE = "floci/floci";
private final String image;
private static final String MIN_VERSION = "1.5.0";
public ImageVersionCheck() {
this("floci/floci");
}
public ImageVersionCheck(String image) {
this.image = image;
}
@Override
public CheckResult run(String endpoint, String container) {
try {
DockerClient docker = new DockerClient();
if (!docker.isImagePresent(IMAGE)) {
return CheckResult.warn("image.version", IMAGE + " not present — version cannot be checked",
if (!docker.isImagePresent(image)) {
return CheckResult.warn("image.version", image + " not present — version cannot be checked",
"floci start --pull always");
}
// Try reading version label from the image
String version = readImageLabel(docker, IMAGE);
String version = readImageLabel(docker, image);
if (version == null) {
return CheckResult.ok("image.version", "Image version unknown (no label); assuming compatible");
}
@@ -28,7 +36,7 @@ public class ImageVersionCheck implements Check {
}
return CheckResult.warn("image.version",
"Server image version " + version + " is below minimum " + MIN_VERSION,
"docker pull " + IMAGE + ":latest");
"docker pull " + image + ":latest");
} catch (DockerException e) {
return CheckResult.warn("image.version", "Could not check image version: " + e.getMessage(), null);
}