mirror of
https://github.com/floci-io/floci-cli.git
synced 2026-11-22 21:50:47 -05:00
refactor!: unify the four product command trees behind ProductProfile (#16)
* refactor!: unify the four product command trees behind ProductProfile
Every shared command now has ONE implementation in commands/,
parameterized by ProductProfile (the single source of per-product
config: endpoint, container, image, env prefix, control prefix,
display name). The gcp/az/oci command classes become ~8-line shims
(GcpStartCommand extends StartCommand { super(ProductProfile.GCP); })
that carry only their per-product help description; the three
near-identical *GlobalOptions clones are deleted. Each product tree
drops from ~1,360 to ~530 lines and copy-drift becomes impossible.
Mechanics: per-product option defaults are constructor-set field
values rendered in help via ${DEFAULT-VALUE} (annotation defaults are
compile-time constants); commands pre-initialize their GlobalOptions
mixin with the profile (picocli uses a non-null mixin field instance
as-is). Verified against a captured baseline of 480 CLI outputs
(every --help x 5 trees, env/status/doctor JSON, exit codes, routing)
plus new pinning tests: ProductProfileTest, ProductTreesParsingTest,
DoctorCheckListTest, GlobalOptionsTest.
Behavior changes, all deliberate:
- snapshot commands in gcp/az/oci trees now perform the real
/snapshots API calls with graceful degradation and exit 1 while the
server lacks the endpoints (previously: note + exit 0)
- product logs/services gained --service/--mode, and services now
resolves the endpoint from the container port mapping in all trees
- the AWS tree brands itself 'Floci AWS' in banners and help,
matching the other products
- snapshot errors link the product issue tracker instead of TODO.md
- completion generates from spec.root() instead of a hardcoded
FlociCli instance (output unchanged)
BREAKING CHANGE: 'floci gcp|az|oci snapshot export/import' (and bare
'floci snapshot ...' with a non-AWS default product) now exit 1
instead of 0 while server-side snapshot support is pending; CI
scripts relying on the silent success of stubbed snapshot commands
will fail.
* fix: snapshot save/load/list/delete resolve the container host port
Same port auto-detection status/services/wait use — a container started
with --port <n> is now reachable by the snapshot commands without an
explicit --endpoint. Applies to all four trees via the unified base
commands.
This commit is contained in:
1 parent
0a65de2303
commit
6dc8fc9df4
100 files changed
+1190
-3283
No files matched your search
@@ -44,18 +44,26 @@ java -jar target/floci.jar <command>
|
||||
|
||||
Bare commands (`floci start`) route to the configured default product (`aws` unless changed via `floci config default-product aws|gcp|az|oci`). Explicit product groups are `floci aws` (same classes as the root tree), `floci gcp`, `floci az`, and `floci oci`.
|
||||
|
||||
### The four product trees — CRITICAL
|
||||
### The unified product tree — CRITICAL
|
||||
|
||||
The GCP (`commands/gcp/`), Azure (`commands/az/`), and OCI (`commands/oci/`) command trees are near-verbatim copies of the root/AWS tree (`commands/`), each with its own `GlobalOptions` variant:
|
||||
There is ONE implementation of every shared command, in `commands/`, parameterized by `ProductProfile` (`io.floci.cli.ProductProfile`) — the single source of per-product config:
|
||||
|
||||
| Tree | Mixin | Default endpoint | Container | Env prefix | Control prefix |
|
||||
|------|-------|------------------|-----------|------------|----------------|
|
||||
| root / `aws` | `GlobalOptions` | `http://localhost:4566` | `floci` | `FLOCI_*` | `/_floci` |
|
||||
| `gcp` | `GcpGlobalOptions` | `http://localhost:4588` | `floci-gcp` | `FLOCI_GCP_*` | `/_floci-gcp` |
|
||||
| `az` | `AzGlobalOptions` | `http://localhost:4577` | `floci-az` | `FLOCI_AZ_*` | `/_floci` (same as AWS — intentional) |
|
||||
| `oci` | `OciGlobalOptions` | `http://localhost:4599` | `floci-oci` | `FLOCI_OCI_*` | `/_floci-oci` |
|
||||
| Profile | Default endpoint | Container | Env prefix | Control prefix |
|
||||
|---------|------------------|-----------|------------|----------------|
|
||||
| `AWS` (root tree) | `http://localhost:4566` | `floci` | `FLOCI_*` | `/_floci` |
|
||||
| `GCP` | `http://localhost:4588` | `floci-gcp` | `FLOCI_GCP_*` | `/_floci-gcp` |
|
||||
| `AZ` | `http://localhost:4577` | `floci-az` | `FLOCI_AZ_*` | `/_floci` (same as AWS — intentional) |
|
||||
| `OCI` | `http://localhost:4599` | `floci-oci` | `FLOCI_OCI_*` | `/_floci-oci` |
|
||||
|
||||
**Until the trees are unified: any change to a shared command MUST be applied to all four trees** (e.g. `StartCommand`, `GcpStartCommand`, `AzStartCommand`, `OciStartCommand`). Drift between the copies is a known bug source — check the sibling trees before and after editing. Only `EnvCommand`/`GcpEnvCommand`/`AzEnvCommand`/`OciEnvCommand` are genuinely product-specific, plus the OCI-only `OciSetupCommand` (the OCI CLI/SDKs require a config file + signing key, so `floci oci setup` scaffolds them; no other tree needs an equivalent).
|
||||
The `commands/gcp/`, `commands/az/`, and `commands/oci/` leaf classes are **~8-line shims**: `GcpStartCommand extends StartCommand { super(ProductProfile.GCP); }` with their own `@Command` annotation carrying the per-product description. `ProductProfileTest` pins every profile field; `ProductTreesParsingTest` pins each tree's defaults.
|
||||
|
||||
Rules for the unified tree:
|
||||
|
||||
- **Every parameterized command pre-initializes its mixin in the constructor**: `this.global = new GlobalOptions(profile)`. Picocli uses a non-null `@Mixin` field instance as-is; a command that forgets gets AWS defaults in every tree (the per-tree parse tests catch this).
|
||||
- **Per-product option defaults are constructor-set field values**, not annotation `defaultValue`s (annotation strings are compile-time constants). Use `(default: ${DEFAULT-VALUE})` in the option description to render them in help.
|
||||
- **Never subclass a group command** (`GcpCommand`, `*ConfigCommand`, `*SnapshotCommand` groups): picocli registers the `subcommands` arrays of both super and subclass — instant duplicate-name crash. Groups stay standalone registration-only classes.
|
||||
- Product-varying strings come from the profile: `displayName()` for banners, `commandPrefix()` for hint strings, `envVar("SERVICES")` for container env vars, `controlPrefix()` for `FlociHttpClient`, `serverRepo()` for issue-tracker links.
|
||||
- Only `EnvCommand`/`GcpEnvCommand`/`AzEnvCommand`/`OciEnvCommand` are genuinely product-specific (not shims), plus the OCI-only `OciSetupCommand` (the OCI CLI/SDKs require a config file + signing key, so `floci oci setup` scaffolds them; no other tree needs an equivalent).
|
||||
|
||||
Commands call `global.printer()` at the start of `call()` — never store a `Printer` as a field.
|
||||
|
||||
@@ -83,12 +91,9 @@ if (printer.format() != OutputFormat.text) {
|
||||
|
||||
`Check` is a `@FunctionalInterface` taking `(endpoint, container)` and returning `CheckResult`. Order matters: Docker checks run before server checks because later checks depend on Docker being up.
|
||||
|
||||
The structure differs per tree (do not assume they match):
|
||||
One `DoctorCommand` serves every tree: `dockerChecks(profile)` builds the 9 Docker/server checks (image and control prefix from the profile), and the constructor appends the product's companion list — `AWS_COMPANION_CHECKS` (AWS CLI checks), `AZ_COMPANION_CHECKS` (az CLI checks), empty for GCP/OCI. `DoctorCheckListTest` pins each product's composition and order.
|
||||
|
||||
- **AWS** (`commands/DoctorCommand.java`): `DOCKER_CHECKS` (static list of the 9 Docker/server checks) + `AWS_COMPANION_CHECKS` (AWS CLI checks), combined via constructor into an instance `allChecks` list.
|
||||
- **GCP/Azure/OCI** (`GcpDoctorCommand`/`AzDoctorCommand`/`OciDoctorCommand`): a single static `ALL_CHECKS` list built in a static initializer.
|
||||
|
||||
To add a check: create a class in `doctor/checks/`, then append it to the relevant list(s) — in all trees where it applies.
|
||||
To add a check: create a class in `doctor/checks/`, then add it to `dockerChecks()` (all products) or the relevant companion list.
|
||||
|
||||
### Config profiles
|
||||
|
||||
|
||||
@@ -7,6 +7,15 @@ This project uses [Semantic Versioning](https://semver.org/).
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
### Changed
|
||||
|
||||
- Internal: the four near-identical product command trees were unified into one `ProductProfile`-parameterized implementation — the `gcp`/`az`/`oci` command classes are now thin subclasses of the root commands, eliminating the copy-drift bug class
|
||||
- **Snapshot commands are now real API calls in every product tree.** `floci gcp|az|oci snapshot save/load/list/delete` call the product server's `/snapshots` control-plane endpoints and degrade gracefully when the server doesn't support them yet — previously they printed a "not yet available" note and exited 0. `snapshot export`/`import` now exit 1 with an error in all four trees (previously exit 0 with a note on gcp/az/oci); CI scripts that relied on the silent success of stubbed snapshot commands will now see failures. Snapshot error messages point at the product's GitHub issue tracker instead of the maintainer-only TODO.md
|
||||
- `floci gcp|az|oci logs` gained the `--service` flag and `services` gained `--mode`, matching the AWS tree (they had drifted apart); `version` on the AWS tree now prints the port-auto-detected endpoint in its "not reachable" hint like the other trees
|
||||
- `services` and `snapshot save/load/list/delete` now auto-detect the endpoint from the running container's port mapping in every tree (like `status`/`wait`/`env` always did), so a container started with `--port <n>` is found without passing `--endpoint`
|
||||
- Global `--endpoint`/`--container` help text now shows each product's default value
|
||||
- The AWS tree now brands itself **Floci AWS** in banners, messages, and help text ("Starting Floci AWS container...", "Floci AWS Doctor", "Show Floci AWS container and server status"), matching the Floci GCP / Floci Azure / Floci OCI naming
|
||||
|
||||
### Added
|
||||
|
||||
- `floci oci` command group — full lifecycle support for the Floci OCI (Oracle Cloud) emulator (`floci-oci`, default port 4599): `start`, `stop`, `restart`, `status`, `logs`, `wait`, `version`, `services`, `doctor`, `env`, `config`, and stub `snapshot` commands, mirroring the GCP/Azure trees. `floci oci env` exports `OCI_CLI_ENDPOINT`, `FLOCI_OCI_ENDPOINT`, and `TF_VAR_CLIENT_HOST_OVERRIDES` for the OCI CLI, the `ocilocal` wrapper, and the `oracle/oci` Terraform provider. `floci config default-product oci` routes bare commands to the OCI tree
|
||||
|
||||
+2
-2
@@ -50,7 +50,7 @@ java -jar target/floci.jar stop
|
||||
|
||||
## Architecture
|
||||
|
||||
See [AGENTS.md](AGENTS.md) for the architecture: command wiring, the four product trees (AWS/GCP/Azure/OCI), the Docker and HTTP I/O boundaries, the output pipeline, native-image constraints, and scope rules.
|
||||
See [AGENTS.md](AGENTS.md) for the architecture: command wiring, the unified `ProductProfile`-parameterized command tree (AWS/GCP/Azure/OCI), the Docker and HTTP I/O boundaries, the output pipeline, native-image constraints, and scope rules.
|
||||
|
||||
`AGENTS.md` is the canonical agent instructions file for this repository, following the [AGENTS.md standard](https://agents.md/). If your coding agent expects a different filename, create a local symlink instead of copying the file:
|
||||
|
||||
@@ -61,7 +61,7 @@ ln -s AGENTS.md GEMINI.md
|
||||
|
||||
### Rules that trip up most PRs
|
||||
|
||||
- **Four product trees.** The `gcp`, `az`, and `oci` command trees mirror the root/AWS tree. A change to a shared command (start, stop, status, logs, wait, doctor, …) must be applied to **all four trees** — `StartCommand`, `GcpStartCommand`, `AzStartCommand`, and `OciStartCommand` — until they are unified.
|
||||
- **One parameterized command tree.** Shared commands live once in `commands/`, parameterized by `ProductProfile`; the `gcp`/`az`/`oci` classes are thin shims (`GcpStartCommand extends StartCommand`). Change the base command and every tree gets it. New per-product values belong in `ProductProfile`, not in command code. Never subclass a group command (duplicate subcommand registration), and always pre-initialize the `GlobalOptions` mixin with the profile in command constructors.
|
||||
- **Native image.** New Jackson DTOs must be registered in `reflect-config.json`; prefer passing `Map`/`JsonNode` to `printer.structured(...)`, which needs no registration. No reflection-heavy dependencies.
|
||||
- **Error messages.** Every `printer.error(...)` must end with a suggested next step:
|
||||
|
||||
|
||||
@@ -584,7 +584,7 @@ floci snapshot export <name> -o tarball.tar.gz
|
||||
floci snapshot import tarball.tar.gz
|
||||
```
|
||||
|
||||
> GCP, Azure, and OCI snapshots (`floci gcp snapshot` / `floci az snapshot` / `floci oci snapshot`) are not yet available — they require server-side endpoints not yet implemented in Floci GCP / Floci Azure / Floci OCI. `floci snapshot export|import` (AWS) are also pending server support.
|
||||
> GCP, Azure, and OCI snapshots (`floci gcp snapshot` / `floci az snapshot` / `floci oci snapshot`) require server-side endpoints not yet implemented in Floci GCP / Floci Azure / Floci OCI — until then those commands report the missing API and exit 1. `floci snapshot export|import` (AWS) are also pending server support and exit 1.
|
||||
|
||||
### `floci update`
|
||||
|
||||
|
||||
@@ -1,80 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package io.floci.cli;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.Properties;
|
||||
|
||||
/** The CLI's own version, read from version.properties stamped at build time. */
|
||||
public final class CliVersion {
|
||||
|
||||
public static final String CLI_VERSION = loadVersion();
|
||||
|
||||
private static String loadVersion() {
|
||||
try (InputStream is = CliVersion.class.getResourceAsStream("/io/floci/cli/version.properties")) {
|
||||
if (is == null) return "unknown";
|
||||
Properties props = new Properties();
|
||||
props.load(is);
|
||||
return props.getProperty("version", "unknown");
|
||||
} catch (Exception e) {
|
||||
return "unknown";
|
||||
}
|
||||
}
|
||||
|
||||
private CliVersion() {}
|
||||
}
|
||||
@@ -55,7 +55,7 @@ public class FlociCli implements Runnable {
|
||||
static class VersionProvider implements IVersionProvider {
|
||||
@Override
|
||||
public String[] getVersion() {
|
||||
return new String[]{"floci " + VersionCommand.CLI_VERSION};
|
||||
return new String[]{"floci " + CliVersion.CLI_VERSION};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,9 +95,9 @@ public class FlociCli implements Runnable {
|
||||
// itself, which already talks about versions.
|
||||
boolean notify = UpdateNotifier.interactiveRunEnabled() && !isUpdateCommand(effectiveArgs);
|
||||
if (notify) {
|
||||
UpdateNotifier.pendingNotice(VersionCommand.CLI_VERSION).ifPresent(latest ->
|
||||
UpdateNotifier.pendingNotice(CliVersion.CLI_VERSION).ifPresent(latest ->
|
||||
System.err.println(Ansi.yellow("A new release of floci is available: "
|
||||
+ VersionCommand.CLI_VERSION + " → " + latest + "\n"
|
||||
+ CliVersion.CLI_VERSION + " → " + latest + "\n"
|
||||
+ "Run 'floci update' to install it") + "\n"));
|
||||
UpdateNotifier.refreshInBackground();
|
||||
}
|
||||
|
||||
@@ -1,83 +0,0 @@
|
||||
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 GcpGlobalOptions {
|
||||
|
||||
/** Control-plane path prefix exposed by the floci-gcp server (differs from AWS/Azure's {@code /_floci}). */
|
||||
public static final String CONTROL_PREFIX = "/_floci-gcp";
|
||||
|
||||
@Option(names = {"--endpoint"},
|
||||
description = "Floci GCP server endpoint URL",
|
||||
defaultValue = "${FLOCI_GCP_ENDPOINT:-http://localhost:4588}",
|
||||
paramLabel = "<url>")
|
||||
public String endpoint;
|
||||
|
||||
@Option(names = {"--container"},
|
||||
description = "Floci GCP container name",
|
||||
defaultValue = "${FLOCI_GCP_CONTAINER:-floci-gcp}",
|
||||
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 = 4588;
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -7,18 +7,32 @@ import io.floci.cli.output.Printer;
|
||||
import picocli.CommandLine.Option;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.function.UnaryOperator;
|
||||
|
||||
/**
|
||||
* Shared global options for every product tree, parameterized by {@link ProductProfile}.
|
||||
*
|
||||
* The per-product defaults for {@code --endpoint} and {@code --container} are set as
|
||||
* field initial values in the constructor (env var override included) instead of
|
||||
* annotation {@code defaultValue}s — annotation strings are compile-time constants and
|
||||
* cannot vary by product. Picocli keeps a parsed-over field's initial value when the
|
||||
* option has no defaultValue, and renders it for {@code ${DEFAULT-VALUE}} in help.
|
||||
*
|
||||
* Commands must pre-initialize their {@code @Mixin GlobalOptions} field in their
|
||||
* constructor (picocli uses a non-null field instance as-is); a command that forgets
|
||||
* gets AWS defaults — covered by the per-tree parse tests.
|
||||
*/
|
||||
public class GlobalOptions {
|
||||
|
||||
public final ProductProfile product;
|
||||
|
||||
@Option(names = {"--endpoint"},
|
||||
description = "Floci server endpoint URL",
|
||||
defaultValue = "${FLOCI_ENDPOINT:-http://localhost:4566}",
|
||||
description = "Floci server endpoint URL (default: ${DEFAULT-VALUE})",
|
||||
paramLabel = "<url>")
|
||||
public String endpoint;
|
||||
|
||||
@Option(names = {"--container"},
|
||||
description = "Floci container name",
|
||||
defaultValue = "${FLOCI_CONTAINER:-floci}",
|
||||
description = "Floci container name (default: ${DEFAULT-VALUE})",
|
||||
paramLabel = "<name>")
|
||||
public String container;
|
||||
|
||||
@@ -42,6 +56,27 @@ public class GlobalOptions {
|
||||
@Option(names = {"--no-color"}, description = "Disable ANSI colors")
|
||||
public boolean noColor;
|
||||
|
||||
public GlobalOptions() {
|
||||
this(ProductProfile.AWS);
|
||||
}
|
||||
|
||||
public GlobalOptions(ProductProfile product) {
|
||||
this(product, System::getenv);
|
||||
}
|
||||
|
||||
/** Test seam: {@code envLookup} replaces {@code System.getenv}. */
|
||||
public GlobalOptions(ProductProfile product, UnaryOperator<String> envLookup) {
|
||||
this.product = product;
|
||||
this.endpoint = envOr(envLookup, product.envVar("ENDPOINT"), product.defaultEndpoint());
|
||||
this.container = envOr(envLookup, product.envVar("CONTAINER"), product.defaultContainer());
|
||||
}
|
||||
|
||||
// Matches picocli's ${VAR:-fallback}: only a NULL env var falls back — empty counts as set.
|
||||
private static String envOr(UnaryOperator<String> env, String var, String fallback) {
|
||||
String value = env.apply(var);
|
||||
return value != null ? value : fallback;
|
||||
}
|
||||
|
||||
public Printer printer() {
|
||||
if (noColor || !isStdoutTty()) {
|
||||
Ansi.disable();
|
||||
@@ -66,7 +101,7 @@ public class GlobalOptions {
|
||||
if (ports == null || ports.isBlank()) return fallback;
|
||||
try {
|
||||
int containerPort = URI.create(fallback).getPort();
|
||||
if (containerPort == -1) containerPort = 4566;
|
||||
if (containerPort == -1) containerPort = product.defaultPort();
|
||||
for (String mapping : ports.trim().split("\\s+")) {
|
||||
int arrow = mapping.indexOf("->");
|
||||
if (arrow < 0) continue;
|
||||
|
||||
@@ -1,83 +0,0 @@
|
||||
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 OciGlobalOptions {
|
||||
|
||||
/** Control-plane path prefix exposed by the floci-oci server (differs from AWS/Azure's {@code /_floci}). */
|
||||
public static final String CONTROL_PREFIX = "/_floci-oci";
|
||||
|
||||
@Option(names = {"--endpoint"},
|
||||
description = "Floci OCI server endpoint URL",
|
||||
defaultValue = "${FLOCI_OCI_ENDPOINT:-http://localhost:4599}",
|
||||
paramLabel = "<url>")
|
||||
public String endpoint;
|
||||
|
||||
@Option(names = {"--container"},
|
||||
description = "Floci OCI container name",
|
||||
defaultValue = "${FLOCI_OCI_CONTAINER:-floci-oci}",
|
||||
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 = 4599;
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -1,22 +1,54 @@
|
||||
package io.floci.cli;
|
||||
|
||||
/**
|
||||
* The single source of per-product configuration for the unified command tree.
|
||||
* Every value that differs between the AWS, GCP, Azure, and OCI emulators lives here;
|
||||
* command classes are parameterized with one of the four constants below.
|
||||
*/
|
||||
public record ProductProfile(
|
||||
String name,
|
||||
String defaultImage,
|
||||
String name, // CLI group name: "aws" | "gcp" | "az" | "oci"
|
||||
String displayName, // banner name: "Floci" | "Floci GCP" | "Floci Azure" | "Floci OCI"
|
||||
String image, // Docker image without tag
|
||||
String defaultContainer,
|
||||
int defaultPort,
|
||||
String endpointEnvVar,
|
||||
String containerEnvVar,
|
||||
String persistPath,
|
||||
String servicesEnvVar
|
||||
String envPrefix, // FLOCI | FLOCI_GCP | FLOCI_AZ | FLOCI_OCI
|
||||
String controlPrefix // control-plane path prefix on the server
|
||||
) {
|
||||
public static final ProductProfile AWS = new ProductProfile(
|
||||
"aws", "floci/floci:latest", "floci", 4566,
|
||||
"FLOCI_ENDPOINT", "FLOCI_CONTAINER", "/var/lib/floci", "FLOCI_SERVICES"
|
||||
);
|
||||
|
||||
public String defaultEndpoint() {
|
||||
return "http://localhost:" + defaultPort;
|
||||
}
|
||||
|
||||
public String defaultImageRef() {
|
||||
return image + ":latest";
|
||||
}
|
||||
|
||||
/** {@code envVar("SERVICES")} → {@code FLOCI_GCP_SERVICES} */
|
||||
public String envVar(String suffix) {
|
||||
return envPrefix + "_" + suffix;
|
||||
}
|
||||
|
||||
/** Command prefix for hint strings: "floci" for aws (the bare tree), "floci gcp" otherwise. */
|
||||
public String commandPrefix() {
|
||||
return "aws".equals(name) ? "floci" : "floci " + name;
|
||||
}
|
||||
|
||||
/** GitHub repository of the product's emulator server, for issue-tracker hints. */
|
||||
public String serverRepo() {
|
||||
return "https://github.com/floci-io/" + ("aws".equals(name) ? "floci" : "floci-" + name);
|
||||
}
|
||||
|
||||
public static final ProductProfile AWS = new ProductProfile(
|
||||
"aws", "Floci AWS", "floci/floci", "floci", 4566, "FLOCI", "/_floci");
|
||||
|
||||
public static final ProductProfile GCP = new ProductProfile(
|
||||
"gcp", "Floci GCP", "floci/floci-gcp", "floci-gcp", 4588, "FLOCI_GCP", "/_floci-gcp");
|
||||
|
||||
// AZ intentionally shares the AWS control prefix /_floci — the floci-az server
|
||||
// exposes /_floci/*, NOT /_floci-az. Do not "fix" this to match the name.
|
||||
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"
|
||||
);
|
||||
"az", "Floci Azure", "floci/floci-az", "floci-az", 4577, "FLOCI_AZ", "/_floci");
|
||||
|
||||
public static final ProductProfile OCI = new ProductProfile(
|
||||
"oci", "Floci OCI", "floci/floci-oci", "floci-oci", 4599, "FLOCI_OCI", "/_floci-oci");
|
||||
}
|
||||
@@ -18,13 +18,19 @@ public class CompletionCommand implements Callable<Integer> {
|
||||
@Mixin
|
||||
GlobalOptions global;
|
||||
|
||||
@Spec
|
||||
Model.CommandSpec spec;
|
||||
|
||||
@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());
|
||||
// The installed shell command is always `floci`, and the root tree contains every
|
||||
// product subtree — so the root script is the correct completion no matter which
|
||||
// group (root, aws, gcp, az, oci) this command was invoked under.
|
||||
CommandLine root = spec.root().commandLine();
|
||||
|
||||
String script = switch (shell.toLowerCase()) {
|
||||
case "bash" -> AutoComplete.bash("floci", root);
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
package io.floci.cli.commands;
|
||||
|
||||
import io.floci.cli.GlobalOptions;
|
||||
import io.floci.cli.ProductProfile;
|
||||
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.AwsCliEndpointCheck;
|
||||
import io.floci.cli.doctor.checks.AwsCliS3PathStyleCheck;
|
||||
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;
|
||||
@@ -29,13 +32,15 @@ import java.util.concurrent.Callable;
|
||||
|
||||
@Command(
|
||||
name = "doctor",
|
||||
description = "Run environment diagnostics for Floci",
|
||||
description = "Run environment diagnostics for Floci AWS",
|
||||
mixinStandardHelpOptions = true
|
||||
)
|
||||
public class DoctorCommand implements Callable<Integer> {
|
||||
|
||||
protected final ProductProfile profile;
|
||||
|
||||
@Mixin
|
||||
GlobalOptions global;
|
||||
protected GlobalOptions global;
|
||||
|
||||
@Option(names = {"--check"}, description = "Run only a specific check by name", paramLabel = "<name>")
|
||||
String checkName;
|
||||
@@ -43,35 +48,50 @@ public class DoctorCommand implements Callable<Integer> {
|
||||
@Option(names = {"--fix"}, description = "Attempt to auto-fix fixable issues")
|
||||
boolean fix;
|
||||
|
||||
public static final List<Check> DOCKER_CHECKS = List.of(
|
||||
new DockerInstalledCheck(),
|
||||
new DockerDaemonCheck(),
|
||||
new DockerSocketCheck(),
|
||||
new DockerVersionCheck(),
|
||||
new PortAvailableCheck(),
|
||||
new ImagePresentCheck(),
|
||||
new ImageVersionCheck(),
|
||||
new ContainerRunningCheck(),
|
||||
new EndpointReachableCheck()
|
||||
);
|
||||
/** The base environment checks every product runs, in order: Docker first, then server. */
|
||||
public static List<Check> dockerChecks(ProductProfile profile) {
|
||||
return List.of(
|
||||
new DockerInstalledCheck(),
|
||||
new DockerDaemonCheck(),
|
||||
new DockerSocketCheck(),
|
||||
new DockerVersionCheck(),
|
||||
new PortAvailableCheck(),
|
||||
new ImagePresentCheck(profile.image()),
|
||||
new ImageVersionCheck(profile.image()),
|
||||
new ContainerRunningCheck(),
|
||||
new EndpointReachableCheck(profile.controlPrefix())
|
||||
);
|
||||
}
|
||||
|
||||
public static final List<Check> AWS_COMPANION_CHECKS = List.of(
|
||||
new AwsCliEndpointCheck(),
|
||||
new AwsCliS3PathStyleCheck()
|
||||
);
|
||||
|
||||
public static final List<Check> AZ_COMPANION_CHECKS = List.of(
|
||||
new AzCliInstalledCheck(),
|
||||
new AzCliConnectionStringCheck()
|
||||
);
|
||||
|
||||
private final List<Check> allChecks;
|
||||
|
||||
public DoctorCommand() {
|
||||
this(AWS_COMPANION_CHECKS);
|
||||
this(ProductProfile.AWS, AWS_COMPANION_CHECKS);
|
||||
}
|
||||
|
||||
public DoctorCommand(List<Check> companionChecks) {
|
||||
List<Check> checks = new ArrayList<>(DOCKER_CHECKS);
|
||||
/** Test seam and shim constructor: base docker checks for the profile + product companions. */
|
||||
public DoctorCommand(ProductProfile profile, List<Check> companionChecks) {
|
||||
this.profile = profile;
|
||||
this.global = new GlobalOptions(profile);
|
||||
List<Check> checks = new ArrayList<>(dockerChecks(profile));
|
||||
checks.addAll(companionChecks);
|
||||
this.allChecks = List.copyOf(checks);
|
||||
}
|
||||
|
||||
public List<Check> allChecks() {
|
||||
return allChecks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer call() {
|
||||
Printer printer = global.printer();
|
||||
@@ -81,7 +101,7 @@ public class DoctorCommand implements Callable<Integer> {
|
||||
boolean textMode = printer.format() == OutputFormat.text;
|
||||
|
||||
if (textMode) {
|
||||
printer.println(Ansi.bold("Floci Doctor") + " — checking your environment");
|
||||
printer.println(Ansi.bold(profile.displayName() + " Doctor") + " — checking your environment");
|
||||
printer.println("");
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ import java.util.concurrent.Callable;
|
||||
|
||||
@Command(
|
||||
name = "env",
|
||||
description = "Print AWS environment variables to connect to Floci",
|
||||
description = "Print AWS environment variables to connect to Floci AWS",
|
||||
mixinStandardHelpOptions = true
|
||||
)
|
||||
public class EnvCommand implements Callable<Integer> {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package io.floci.cli.commands;
|
||||
|
||||
import io.floci.cli.GlobalOptions;
|
||||
import io.floci.cli.ProductProfile;
|
||||
import io.floci.cli.docker.DockerClient;
|
||||
import io.floci.cli.docker.DockerException;
|
||||
import io.floci.cli.output.Printer;
|
||||
@@ -10,13 +11,24 @@ import java.util.concurrent.Callable;
|
||||
|
||||
@Command(
|
||||
name = "logs",
|
||||
description = "Fetch logs from the Floci container",
|
||||
description = "Fetch logs from the Floci AWS container",
|
||||
mixinStandardHelpOptions = true
|
||||
)
|
||||
public class LogsCommand implements Callable<Integer> {
|
||||
|
||||
protected final ProductProfile profile;
|
||||
|
||||
@Mixin
|
||||
GlobalOptions global;
|
||||
protected GlobalOptions global;
|
||||
|
||||
public LogsCommand() {
|
||||
this(ProductProfile.AWS);
|
||||
}
|
||||
|
||||
protected LogsCommand(ProductProfile profile) {
|
||||
this.profile = profile;
|
||||
this.global = new GlobalOptions(profile);
|
||||
}
|
||||
|
||||
@Option(names = {"--follow", "-f"}, description = "Follow log output")
|
||||
boolean follow;
|
||||
@@ -38,7 +50,7 @@ public class LogsCommand implements Callable<Integer> {
|
||||
try {
|
||||
var info = docker.inspectContainer(global.container);
|
||||
if (info.isEmpty()) {
|
||||
printer.error("Container '" + global.container + "' not found.\nRun 'floci start' to launch one.");
|
||||
printer.error("Container '" + global.container + "' not found.\nRun '" + profile.commandPrefix() + " start' to launch one.");
|
||||
return 1;
|
||||
}
|
||||
} catch (DockerException e) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package io.floci.cli.commands;
|
||||
|
||||
import io.floci.cli.GlobalOptions;
|
||||
import io.floci.cli.ProductProfile;
|
||||
import io.floci.cli.output.Printer;
|
||||
import picocli.CommandLine.*;
|
||||
|
||||
@@ -8,19 +9,30 @@ import java.util.concurrent.Callable;
|
||||
|
||||
@Command(
|
||||
name = "restart",
|
||||
description = "Stop and restart the Floci container",
|
||||
description = "Stop and restart the Floci AWS container",
|
||||
mixinStandardHelpOptions = true
|
||||
)
|
||||
public class RestartCommand implements Callable<Integer> {
|
||||
|
||||
protected final ProductProfile profile;
|
||||
|
||||
@Mixin
|
||||
GlobalOptions global;
|
||||
protected GlobalOptions global;
|
||||
|
||||
public RestartCommand() {
|
||||
this(ProductProfile.AWS);
|
||||
}
|
||||
|
||||
protected RestartCommand(ProductProfile profile) {
|
||||
this.profile = profile;
|
||||
this.global = new GlobalOptions(profile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer call() {
|
||||
Printer printer = global.printer();
|
||||
|
||||
StopCommand stop = new StopCommand();
|
||||
StopCommand stop = new StopCommand(profile);
|
||||
stop.global = global;
|
||||
stop.remove = false;
|
||||
stop.timeout = 10;
|
||||
@@ -30,11 +42,11 @@ public class RestartCommand implements Callable<Integer> {
|
||||
// Minimal wait to avoid port-already-in-use races
|
||||
try { Thread.sleep(1000); } catch (InterruptedException e) { Thread.currentThread().interrupt(); }
|
||||
|
||||
StartCommand start = new StartCommand();
|
||||
StartCommand start = new StartCommand(profile);
|
||||
start.global = global;
|
||||
start.port = 4566;
|
||||
start.port = profile.defaultPort();
|
||||
start.pull = "missing";
|
||||
start.image = "floci/floci:latest";
|
||||
start.image = profile.defaultImageRef();
|
||||
start.detach = false;
|
||||
return start.call();
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package io.floci.cli.commands;
|
||||
|
||||
import io.floci.cli.GlobalOptions;
|
||||
import io.floci.cli.ProductProfile;
|
||||
import io.floci.cli.docker.DockerClient;
|
||||
import io.floci.cli.http.FlociHttpClient;
|
||||
import io.floci.cli.output.Ansi;
|
||||
import io.floci.cli.output.OutputFormat;
|
||||
@@ -14,13 +16,24 @@ import java.util.concurrent.Callable;
|
||||
|
||||
@Command(
|
||||
name = "services",
|
||||
description = "List services available in the running Floci instance",
|
||||
description = "List services available in the running Floci AWS instance",
|
||||
mixinStandardHelpOptions = true
|
||||
)
|
||||
public class ServicesCommand implements Callable<Integer> {
|
||||
|
||||
protected final ProductProfile profile;
|
||||
|
||||
@Mixin
|
||||
GlobalOptions global;
|
||||
protected GlobalOptions global;
|
||||
|
||||
public ServicesCommand() {
|
||||
this(ProductProfile.AWS);
|
||||
}
|
||||
|
||||
protected ServicesCommand(ProductProfile profile) {
|
||||
this.profile = profile;
|
||||
this.global = new GlobalOptions(profile);
|
||||
}
|
||||
|
||||
@Option(names = {"--mode"}, description = "Filter mode: docker, in-process, all (default: all)", defaultValue = "all", paramLabel = "docker|in-process|all")
|
||||
String mode;
|
||||
@@ -28,14 +41,18 @@ public class ServicesCommand implements Callable<Integer> {
|
||||
@Override
|
||||
public Integer call() {
|
||||
Printer printer = global.printer();
|
||||
FlociHttpClient client = new FlociHttpClient(global.endpoint);
|
||||
// Resolve the endpoint from the container's port mapping, like status/wait/env do,
|
||||
// so a container started with --port <n> is still found without --endpoint.
|
||||
String effectiveEndpoint = global.resolvedEndpoint(new DockerClient());
|
||||
FlociHttpClient client = new FlociHttpClient(effectiveEndpoint, profile.controlPrefix());
|
||||
|
||||
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'.");
|
||||
printer.error("Could not reach " + profile.displayName() + " at " + effectiveEndpoint
|
||||
+ ".\nIs " + profile.displayName() + " running? Try '" + profile.commandPrefix() + " start'.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -44,7 +61,7 @@ public class ServicesCommand implements Callable<Integer> {
|
||||
return 0;
|
||||
}
|
||||
|
||||
printer.println(Ansi.bold("Floci Services") + " " + Ansi.gray("(" + services.size() + " enabled)"));
|
||||
printer.println(Ansi.bold(profile.displayName() + " Services") + " " + Ansi.gray("(" + services.size() + " enabled)"));
|
||||
printer.println("");
|
||||
for (String svc : services) {
|
||||
printer.println(" " + Ansi.green("✓") + " " + svc);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package io.floci.cli.commands;
|
||||
|
||||
import io.floci.cli.GlobalOptions;
|
||||
import io.floci.cli.ProductProfile;
|
||||
import io.floci.cli.docker.DockerClient;
|
||||
import io.floci.cli.docker.DockerException;
|
||||
import io.floci.cli.output.Ansi;
|
||||
@@ -13,15 +14,28 @@ import java.util.concurrent.Callable;
|
||||
|
||||
@Command(
|
||||
name = "start",
|
||||
description = "Start the Floci container",
|
||||
description = "Start the Floci AWS emulator container",
|
||||
mixinStandardHelpOptions = true
|
||||
)
|
||||
public class StartCommand implements Callable<Integer> {
|
||||
|
||||
@Mixin
|
||||
GlobalOptions global;
|
||||
protected final ProductProfile profile;
|
||||
|
||||
@Option(names = {"--port"}, description = "Host port to bind (default: 4566)", defaultValue = "4566", paramLabel = "<port>")
|
||||
@Mixin
|
||||
protected GlobalOptions global;
|
||||
|
||||
public StartCommand() {
|
||||
this(ProductProfile.AWS);
|
||||
}
|
||||
|
||||
protected StartCommand(ProductProfile profile) {
|
||||
this.profile = profile;
|
||||
this.global = new GlobalOptions(profile);
|
||||
this.port = profile.defaultPort();
|
||||
this.image = profile.defaultImageRef();
|
||||
}
|
||||
|
||||
@Option(names = {"--port"}, description = "Host port to bind (default: ${DEFAULT-VALUE})", paramLabel = "<port>")
|
||||
int port;
|
||||
|
||||
@Option(names = {"--persist"}, description = "Host directory for persistent state", paramLabel = "<dir>")
|
||||
@@ -33,7 +47,7 @@ public class StartCommand implements Callable<Integer> {
|
||||
@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>")
|
||||
@Option(names = {"--image"}, description = "Image reference to use (default: ${DEFAULT-VALUE})", paramLabel = "<ref>")
|
||||
String image;
|
||||
|
||||
@Option(names = {"--pull"}, description = "Image pull policy: always, missing, never", defaultValue = "missing", paramLabel = "always|missing|never")
|
||||
@@ -56,7 +70,7 @@ public class StartCommand implements Callable<Integer> {
|
||||
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.");
|
||||
printer.error("Container '" + global.container + "' is already running.\nRun '" + profile.commandPrefix() + " stop' first or pass --container <name> to use a different name.");
|
||||
return 1;
|
||||
}
|
||||
// Remove stopped container so we can start fresh
|
||||
@@ -73,28 +87,28 @@ public class StartCommand implements Callable<Integer> {
|
||||
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.");
|
||||
printer.error("Failed to pull image: " + e.getMessage() + "\nRun '" + profile.commandPrefix() + " 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("-p", port + ":" + profile.defaultPort()));
|
||||
args.addAll(DockerClient.dockerSocketRunArgs());
|
||||
if (persistDir != null) {
|
||||
args.addAll(List.of("-v", persistDir + ":/app/data"));
|
||||
// The server defaults to in-memory storage; enable persistent mode so
|
||||
// state is actually written to the mounted directory and survives restarts.
|
||||
args.addAll(List.of("-e", "FLOCI_STORAGE_MODE=persistent"));
|
||||
args.addAll(List.of("-e", profile.envVar("STORAGE_MODE") + "=persistent"));
|
||||
}
|
||||
if (services != null && !services.isBlank()) {
|
||||
args.addAll(List.of("-e", "FLOCI_SERVICES=" + services));
|
||||
args.addAll(List.of("-e", profile.envVar("SERVICES") + "=" + services));
|
||||
}
|
||||
args.add(image);
|
||||
|
||||
try {
|
||||
printer.println("Starting " + Ansi.gold("Floci") + " container...");
|
||||
printer.println("Starting " + Ansi.gold(profile.displayName()) + " container...");
|
||||
String id = docker.startContainer(args);
|
||||
printer.println(Ansi.green("Container started") + " (" + id.substring(0, Math.min(12, id.length())) + ")");
|
||||
} catch (DockerException e) {
|
||||
@@ -103,7 +117,7 @@ public class StartCommand implements Callable<Integer> {
|
||||
}
|
||||
|
||||
if (detach) {
|
||||
printer.println(Ansi.gray("Detached. Run 'floci wait' to poll for readiness."));
|
||||
printer.println(Ansi.gray("Detached. Run '" + profile.commandPrefix() + " wait' to poll for readiness."));
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -111,8 +125,8 @@ public class StartCommand implements Callable<Integer> {
|
||||
global.endpoint = "http://localhost:" + port;
|
||||
|
||||
// Wait for readiness
|
||||
printer.println(Ansi.gray("Waiting for Floci to be ready..."));
|
||||
WaitCommand wait = new WaitCommand();
|
||||
printer.println(Ansi.gray("Waiting for " + profile.displayName() + " to be ready..."));
|
||||
WaitCommand wait = new WaitCommand(profile);
|
||||
wait.global = global;
|
||||
wait.timeout = "30s";
|
||||
return wait.call();
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package io.floci.cli.commands;
|
||||
|
||||
import io.floci.cli.GlobalOptions;
|
||||
import io.floci.cli.ProductProfile;
|
||||
import io.floci.cli.docker.DockerClient;
|
||||
import io.floci.cli.docker.DockerException;
|
||||
import io.floci.cli.http.FlociHttpClient;
|
||||
@@ -16,13 +17,24 @@ import java.util.concurrent.Callable;
|
||||
|
||||
@Command(
|
||||
name = "status",
|
||||
description = "Show Floci container and server status",
|
||||
description = "Show Floci AWS container and server status",
|
||||
mixinStandardHelpOptions = true
|
||||
)
|
||||
public class StatusCommand implements Callable<Integer> {
|
||||
|
||||
protected final ProductProfile profile;
|
||||
|
||||
@Mixin
|
||||
GlobalOptions global;
|
||||
protected GlobalOptions global;
|
||||
|
||||
public StatusCommand() {
|
||||
this(ProductProfile.AWS);
|
||||
}
|
||||
|
||||
protected StatusCommand(ProductProfile profile) {
|
||||
this.profile = profile;
|
||||
this.global = new GlobalOptions(profile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer call() {
|
||||
@@ -50,7 +62,7 @@ public class StatusCommand implements Callable<Integer> {
|
||||
String serverVersion = "unavailable";
|
||||
String serverEdition = "";
|
||||
boolean reachable = false;
|
||||
FlociHttpClient client = new FlociHttpClient(effectiveEndpoint);
|
||||
FlociHttpClient client = new FlociHttpClient(effectiveEndpoint, profile.controlPrefix());
|
||||
try {
|
||||
var health = client.health();
|
||||
serverVersion = health.version();
|
||||
@@ -73,7 +85,7 @@ public class StatusCommand implements Callable<Integer> {
|
||||
return 0;
|
||||
}
|
||||
|
||||
printer.println(Ansi.bold("Floci Status"));
|
||||
printer.println(Ansi.bold(profile.displayName() + " Status"));
|
||||
printer.println("");
|
||||
String stateColor = switch (containerState) {
|
||||
case "running" -> Ansi.green(containerState);
|
||||
@@ -92,7 +104,7 @@ public class StatusCommand implements Callable<Integer> {
|
||||
|
||||
if (!reachable && !"running".equals(containerState)) {
|
||||
printer.println("");
|
||||
printer.println(Ansi.gray("Run 'floci start' to launch Floci."));
|
||||
printer.println(Ansi.gray("Run '" + profile.commandPrefix() + " start' to launch " + profile.displayName() + "."));
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package io.floci.cli.commands;
|
||||
|
||||
import io.floci.cli.GlobalOptions;
|
||||
import io.floci.cli.ProductProfile;
|
||||
import io.floci.cli.docker.DockerClient;
|
||||
import io.floci.cli.docker.DockerException;
|
||||
import io.floci.cli.output.Ansi;
|
||||
@@ -11,13 +12,24 @@ import java.util.concurrent.Callable;
|
||||
|
||||
@Command(
|
||||
name = "stop",
|
||||
description = "Stop the Floci container",
|
||||
description = "Stop the Floci AWS container",
|
||||
mixinStandardHelpOptions = true
|
||||
)
|
||||
public class StopCommand implements Callable<Integer> {
|
||||
|
||||
protected final ProductProfile profile;
|
||||
|
||||
@Mixin
|
||||
GlobalOptions global;
|
||||
protected GlobalOptions global;
|
||||
|
||||
public StopCommand() {
|
||||
this(ProductProfile.AWS);
|
||||
}
|
||||
|
||||
protected StopCommand(ProductProfile profile) {
|
||||
this.profile = profile;
|
||||
this.global = new GlobalOptions(profile);
|
||||
}
|
||||
|
||||
@Option(names = {"--remove", "-r"}, description = "Remove the container after stopping")
|
||||
boolean remove;
|
||||
@@ -33,7 +45,7 @@ public class StopCommand implements Callable<Integer> {
|
||||
try {
|
||||
var info = docker.inspectContainer(global.container);
|
||||
if (info.isEmpty()) {
|
||||
printer.error("Container '" + global.container + "' not found.\nRun 'floci start' to launch one.");
|
||||
printer.error("Container '" + global.container + "' not found.\nRun '" + profile.commandPrefix() + " start' to launch one.");
|
||||
return 1;
|
||||
}
|
||||
if (!"running".equals(info.get().state())) {
|
||||
@@ -50,7 +62,7 @@ public class StopCommand implements Callable<Integer> {
|
||||
}
|
||||
|
||||
try {
|
||||
printer.println("Stopping " + Ansi.gold("Floci") + " container '" + global.container + "'...");
|
||||
printer.println("Stopping " + Ansi.gold(profile.displayName()) + " container '" + global.container + "'...");
|
||||
docker.stopContainer(global.container, timeout);
|
||||
printer.println(Ansi.green("Stopped."));
|
||||
} catch (DockerException e) {
|
||||
|
||||
@@ -2,6 +2,7 @@ package io.floci.cli.commands;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.floci.cli.CliVersion;
|
||||
import io.floci.cli.output.Ansi;
|
||||
import io.floci.cli.output.OutputFormat;
|
||||
import io.floci.cli.output.Printer;
|
||||
@@ -72,7 +73,7 @@ public class UpdateCommand implements Callable<Integer> {
|
||||
}
|
||||
Printer printer = new Printer(System.out, System.err, OutputFormat.text, false);
|
||||
try {
|
||||
String current = VersionCommand.CLI_VERSION;
|
||||
String current = CliVersion.CLI_VERSION;
|
||||
boolean pinned = to != null && !to.isBlank();
|
||||
String target = pinned ? to.trim() : fetchLatestVersion();
|
||||
|
||||
|
||||
@@ -1,41 +1,39 @@
|
||||
package io.floci.cli.commands;
|
||||
|
||||
import io.floci.cli.CliVersion;
|
||||
import io.floci.cli.GlobalOptions;
|
||||
import io.floci.cli.ProductProfile;
|
||||
import io.floci.cli.http.FlociHttpClient;
|
||||
import io.floci.cli.output.Ansi;
|
||||
import io.floci.cli.output.OutputFormat;
|
||||
import io.floci.cli.output.Printer;
|
||||
import picocli.CommandLine.*;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
@Command(
|
||||
name = "version",
|
||||
description = "Show CLI version, connected server version, and image digest",
|
||||
description = "Show CLI version, connected Floci AWS server version, and image digest",
|
||||
mixinStandardHelpOptions = true
|
||||
)
|
||||
public class VersionCommand implements Callable<Integer> {
|
||||
|
||||
public static final String CLI_VERSION = loadVersion();
|
||||
|
||||
private static String loadVersion() {
|
||||
try (InputStream is = VersionCommand.class.getResourceAsStream("/io/floci/cli/version.properties")) {
|
||||
if (is == null) return "unknown";
|
||||
Properties props = new Properties();
|
||||
props.load(is);
|
||||
return props.getProperty("version", "unknown");
|
||||
} catch (Exception e) {
|
||||
return "unknown";
|
||||
}
|
||||
}
|
||||
protected final ProductProfile profile;
|
||||
|
||||
@Mixin
|
||||
GlobalOptions global;
|
||||
protected GlobalOptions global;
|
||||
|
||||
public VersionCommand() {
|
||||
this(ProductProfile.AWS);
|
||||
}
|
||||
|
||||
protected VersionCommand(ProductProfile profile) {
|
||||
this.profile = profile;
|
||||
this.global = new GlobalOptions(profile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer call() {
|
||||
@@ -48,7 +46,7 @@ public class VersionCommand implements Callable<Integer> {
|
||||
var docker = new io.floci.cli.docker.DockerClient();
|
||||
String effectiveEndpoint = global.resolvedEndpoint(docker);
|
||||
|
||||
FlociHttpClient client = new FlociHttpClient(effectiveEndpoint);
|
||||
FlociHttpClient client = new FlociHttpClient(effectiveEndpoint, profile.controlPrefix());
|
||||
try {
|
||||
var info = client.info();
|
||||
serverVersion = info.version();
|
||||
@@ -57,11 +55,11 @@ public class VersionCommand implements Callable<Integer> {
|
||||
|
||||
// Try to read image digest from Docker (best-effort)
|
||||
try {
|
||||
imageDigest = docker.imageDigest("floci/floci").orElse(null);
|
||||
imageDigest = docker.imageDigest(profile.image()).orElse(null);
|
||||
} catch (Exception ignored) {}
|
||||
|
||||
Map<String, Object> data = new LinkedHashMap<>();
|
||||
data.put("cli", CLI_VERSION);
|
||||
data.put("cli", CliVersion.CLI_VERSION);
|
||||
data.put("server", Optional.ofNullable(serverVersion).orElse("unavailable"));
|
||||
data.put("edition", Optional.ofNullable(serverEdition).orElse(""));
|
||||
if (imageDigest != null) data.put("digest", imageDigest);
|
||||
@@ -71,11 +69,13 @@ public class VersionCommand implements Callable<Integer> {
|
||||
return 0;
|
||||
}
|
||||
|
||||
printer.println(Ansi.bold("Floci CLI") + " " + Ansi.gold(CLI_VERSION));
|
||||
printer.println(Ansi.bold("Floci CLI") + " " + Ansi.gold(CliVersion.CLI_VERSION));
|
||||
if (serverVersion != null) {
|
||||
printer.println("Server: " + serverVersion + (serverEdition != null ? " (" + serverEdition + ")" : ""));
|
||||
} else {
|
||||
printer.println("Server: " + Ansi.gray("not reachable at " + global.endpoint));
|
||||
// Effective endpoint (port auto-detected) — the gcp/az/oci trees always did
|
||||
// this; the old AWS copy printed the raw --endpoint value.
|
||||
printer.println("Server: " + Ansi.gray("not reachable at " + effectiveEndpoint));
|
||||
}
|
||||
if (imageDigest != null) {
|
||||
printer.println("Image: " + imageDigest);
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package io.floci.cli.commands;
|
||||
|
||||
import io.floci.cli.GlobalOptions;
|
||||
import io.floci.cli.ProductProfile;
|
||||
import io.floci.cli.http.FlociHttpClient;
|
||||
import io.floci.cli.util.Durations;
|
||||
import io.floci.cli.output.Ansi;
|
||||
import io.floci.cli.output.OutputFormat;
|
||||
import io.floci.cli.output.Printer;
|
||||
@@ -15,13 +17,24 @@ import java.util.concurrent.Callable;
|
||||
|
||||
@Command(
|
||||
name = "wait",
|
||||
description = "Wait until Floci is ready to accept requests",
|
||||
description = "Wait until Floci AWS is ready to accept requests",
|
||||
mixinStandardHelpOptions = true
|
||||
)
|
||||
public class WaitCommand implements Callable<Integer> {
|
||||
|
||||
protected final ProductProfile profile;
|
||||
|
||||
@Mixin
|
||||
GlobalOptions global;
|
||||
protected GlobalOptions global;
|
||||
|
||||
public WaitCommand() {
|
||||
this(ProductProfile.AWS);
|
||||
}
|
||||
|
||||
protected WaitCommand(ProductProfile profile) {
|
||||
this.profile = profile;
|
||||
this.global = new GlobalOptions(profile);
|
||||
}
|
||||
|
||||
@Option(names = {"--timeout"}, description = "Maximum time to wait (e.g. 30s, 2m)", defaultValue = "30s", paramLabel = "<duration>")
|
||||
String timeout;
|
||||
@@ -32,9 +45,9 @@ public class WaitCommand implements Callable<Integer> {
|
||||
@Override
|
||||
public Integer call() {
|
||||
Printer printer = global.printer();
|
||||
long timeoutMillis = parseDuration(timeout);
|
||||
long timeoutMillis = Durations.parseDuration(timeout);
|
||||
String effectiveEndpoint = global.resolvedEndpoint(new io.floci.cli.docker.DockerClient());
|
||||
FlociHttpClient client = new FlociHttpClient(effectiveEndpoint);
|
||||
FlociHttpClient client = new FlociHttpClient(effectiveEndpoint, profile.controlPrefix());
|
||||
Instant deadline = Instant.now().plusMillis(timeoutMillis);
|
||||
|
||||
while (Instant.now().isBefore(deadline)) {
|
||||
@@ -42,7 +55,7 @@ public class WaitCommand implements Callable<Integer> {
|
||||
if (printer.format() != OutputFormat.text) {
|
||||
printer.structured(Map.of("ready", true, "endpoint", effectiveEndpoint));
|
||||
} else {
|
||||
printer.println(Ansi.green("Floci is ready") + " (" + effectiveEndpoint + ")");
|
||||
printer.println(Ansi.green(profile.displayName() + " is ready") + " (" + effectiveEndpoint + ")");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -53,7 +66,8 @@ public class WaitCommand implements Callable<Integer> {
|
||||
}
|
||||
}
|
||||
|
||||
printer.error("Timed out waiting for Floci after " + timeout + ".\nIs the container running? Try 'floci status'.");
|
||||
printer.error("Timed out waiting for " + profile.displayName() + " after " + timeout
|
||||
+ ".\nIs the container running? Try '" + profile.commandPrefix() + " status'.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -75,13 +89,4 @@ public class WaitCommand implements Callable<Integer> {
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -1,116 +1,19 @@
|
||||
package io.floci.cli.commands.az;
|
||||
|
||||
import io.floci.cli.AzGlobalOptions;
|
||||
import io.floci.cli.ProductProfile;
|
||||
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 picocli.CommandLine.Command;
|
||||
|
||||
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> {
|
||||
public class AzDoctorCommand extends DoctorCommand {
|
||||
|
||||
@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;
|
||||
public AzDoctorCommand() {
|
||||
super(ProductProfile.AZ, AZ_COMPANION_CHECKS);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package io.floci.cli.commands.az;
|
||||
|
||||
import io.floci.cli.AzGlobalOptions;
|
||||
import io.floci.cli.GlobalOptions;
|
||||
import io.floci.cli.ProductProfile;
|
||||
import io.floci.cli.docker.DockerClient;
|
||||
import io.floci.cli.doctor.checks.AzCliConnectionStringCheck;
|
||||
import io.floci.cli.output.Ansi;
|
||||
@@ -31,7 +32,7 @@ public class AzEnvCommand implements Callable<Integer> {
|
||||
Set.of("blob", "queue", "table", "functions", "app-config", "key-vault");
|
||||
|
||||
@Mixin
|
||||
AzGlobalOptions global;
|
||||
GlobalOptions global = new GlobalOptions(ProductProfile.AZ);
|
||||
|
||||
@Option(names = {"--format"},
|
||||
description = "Output mode: connection-string, sdk-vars (default: connection-string)",
|
||||
|
||||
@@ -1,54 +1,17 @@
|
||||
package io.floci.cli.commands.az;
|
||||
|
||||
import io.floci.cli.AzGlobalOptions;
|
||||
import io.floci.cli.docker.DockerClient;
|
||||
import io.floci.cli.docker.DockerException;
|
||||
import io.floci.cli.output.Printer;
|
||||
import picocli.CommandLine.*;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
import io.floci.cli.ProductProfile;
|
||||
import io.floci.cli.commands.LogsCommand;
|
||||
import picocli.CommandLine.Command;
|
||||
|
||||
@Command(
|
||||
name = "logs",
|
||||
description = "Fetch logs from the Floci Azure container",
|
||||
mixinStandardHelpOptions = true
|
||||
)
|
||||
public class AzLogsCommand implements Callable<Integer> {
|
||||
public class AzLogsCommand extends LogsCommand {
|
||||
|
||||
@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;
|
||||
}
|
||||
public AzLogsCommand() {
|
||||
super(ProductProfile.AZ);
|
||||
}
|
||||
}
|
||||
@@ -1,40 +1,17 @@
|
||||
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;
|
||||
import io.floci.cli.ProductProfile;
|
||||
import io.floci.cli.commands.RestartCommand;
|
||||
import picocli.CommandLine.Command;
|
||||
|
||||
@Command(
|
||||
name = "restart",
|
||||
description = "Stop and restart the Floci Azure container",
|
||||
mixinStandardHelpOptions = true
|
||||
)
|
||||
public class AzRestartCommand implements Callable<Integer> {
|
||||
public class AzRestartCommand extends RestartCommand {
|
||||
|
||||
@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();
|
||||
public AzRestartCommand() {
|
||||
super(ProductProfile.AZ);
|
||||
}
|
||||
}
|
||||
@@ -1,55 +1,17 @@
|
||||
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;
|
||||
import io.floci.cli.ProductProfile;
|
||||
import io.floci.cli.commands.ServicesCommand;
|
||||
import picocli.CommandLine.Command;
|
||||
|
||||
@Command(
|
||||
name = "services",
|
||||
description = "List services available in the running Floci Azure instance",
|
||||
mixinStandardHelpOptions = true
|
||||
)
|
||||
public class AzServicesCommand implements Callable<Integer> {
|
||||
public class AzServicesCommand extends ServicesCommand {
|
||||
|
||||
@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;
|
||||
public AzServicesCommand() {
|
||||
super(ProductProfile.AZ);
|
||||
}
|
||||
}
|
||||
@@ -1,113 +1,17 @@
|
||||
package io.floci.cli.commands.az;
|
||||
|
||||
import io.floci.cli.AzGlobalOptions;
|
||||
import io.floci.cli.docker.DockerClient;
|
||||
import io.floci.cli.docker.DockerException;
|
||||
import io.floci.cli.output.Ansi;
|
||||
import io.floci.cli.output.Printer;
|
||||
import picocli.CommandLine.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Callable;
|
||||
import io.floci.cli.ProductProfile;
|
||||
import io.floci.cli.commands.StartCommand;
|
||||
import picocli.CommandLine.Command;
|
||||
|
||||
@Command(
|
||||
name = "start",
|
||||
description = "Start the Floci Azure emulator container",
|
||||
mixinStandardHelpOptions = true
|
||||
)
|
||||
public class AzStartCommand implements Callable<Integer> {
|
||||
public class AzStartCommand extends StartCommand {
|
||||
|
||||
@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(DockerClient.dockerSocketRunArgs());
|
||||
if (persistDir != null) {
|
||||
args.addAll(List.of("-v", persistDir + ":/app/data"));
|
||||
// The server defaults to in-memory storage; enable persistent mode so
|
||||
// state is actually written to the mounted directory and survives restarts.
|
||||
args.addAll(List.of("-e", "FLOCI_AZ_STORAGE_MODE=persistent"));
|
||||
}
|
||||
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();
|
||||
public AzStartCommand() {
|
||||
super(ProductProfile.AZ);
|
||||
}
|
||||
}
|
||||
@@ -1,98 +1,17 @@
|
||||
package io.floci.cli.commands.az;
|
||||
|
||||
import io.floci.cli.AzGlobalOptions;
|
||||
import io.floci.cli.docker.DockerClient;
|
||||
import io.floci.cli.docker.DockerException;
|
||||
import io.floci.cli.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;
|
||||
import io.floci.cli.ProductProfile;
|
||||
import io.floci.cli.commands.StatusCommand;
|
||||
import picocli.CommandLine.Command;
|
||||
|
||||
@Command(
|
||||
name = "status",
|
||||
description = "Show Floci Azure container and server status",
|
||||
mixinStandardHelpOptions = true
|
||||
)
|
||||
public class AzStatusCommand implements Callable<Integer> {
|
||||
public class AzStatusCommand extends StatusCommand {
|
||||
|
||||
@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;
|
||||
public AzStatusCommand() {
|
||||
super(ProductProfile.AZ);
|
||||
}
|
||||
}
|
||||
@@ -1,73 +1,17 @@
|
||||
package io.floci.cli.commands.az;
|
||||
|
||||
import io.floci.cli.AzGlobalOptions;
|
||||
import io.floci.cli.docker.DockerClient;
|
||||
import io.floci.cli.docker.DockerException;
|
||||
import io.floci.cli.output.Ansi;
|
||||
import io.floci.cli.output.Printer;
|
||||
import picocli.CommandLine.*;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
import io.floci.cli.ProductProfile;
|
||||
import io.floci.cli.commands.StopCommand;
|
||||
import picocli.CommandLine.Command;
|
||||
|
||||
@Command(
|
||||
name = "stop",
|
||||
description = "Stop the Floci Azure container",
|
||||
mixinStandardHelpOptions = true
|
||||
)
|
||||
public class AzStopCommand implements Callable<Integer> {
|
||||
public class AzStopCommand extends StopCommand {
|
||||
|
||||
@Mixin
|
||||
AzGlobalOptions global;
|
||||
|
||||
@Option(names = {"--remove", "-r"}, description = "Remove the container after stopping")
|
||||
boolean remove;
|
||||
|
||||
@Option(names = {"--timeout"}, description = "Seconds to wait before forcefully killing (default: 10)", defaultValue = "10", paramLabel = "<seconds>")
|
||||
int timeout;
|
||||
|
||||
@Override
|
||||
public Integer call() {
|
||||
Printer printer = global.printer();
|
||||
DockerClient docker = new DockerClient();
|
||||
|
||||
try {
|
||||
var info = docker.inspectContainer(global.container);
|
||||
if (info.isEmpty()) {
|
||||
printer.error("Container '" + global.container + "' not found.\nRun 'floci az start' to launch one.");
|
||||
return 1;
|
||||
}
|
||||
if (!"running".equals(info.get().state())) {
|
||||
printer.println(Ansi.yellow("Container '" + global.container + "' is not running (state: " + info.get().state() + ")"));
|
||||
if (remove) {
|
||||
docker.removeContainer(global.container);
|
||||
printer.println("Container removed.");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
} catch (DockerException e) {
|
||||
printer.error("Failed to inspect container: " + e.getMessage());
|
||||
return 1;
|
||||
}
|
||||
|
||||
try {
|
||||
printer.println("Stopping " + Ansi.gold("Floci Azure") + " container '" + global.container + "'...");
|
||||
docker.stopContainer(global.container, timeout);
|
||||
printer.println(Ansi.green("Stopped."));
|
||||
} catch (DockerException e) {
|
||||
printer.error("Failed to stop container: " + e.getMessage());
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (remove) {
|
||||
try {
|
||||
docker.removeContainer(global.container);
|
||||
printer.println("Container removed.");
|
||||
} catch (DockerException e) {
|
||||
printer.error("Failed to remove container: " + e.getMessage());
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
public AzStopCommand() {
|
||||
super(ProductProfile.AZ);
|
||||
}
|
||||
}
|
||||
@@ -1,72 +1,17 @@
|
||||
package io.floci.cli.commands.az;
|
||||
|
||||
import io.floci.cli.AzGlobalOptions;
|
||||
import io.floci.cli.ProductProfile;
|
||||
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;
|
||||
import picocli.CommandLine.Command;
|
||||
|
||||
@Command(
|
||||
name = "version",
|
||||
description = "Show CLI version, connected Floci Azure server version, and image digest",
|
||||
mixinStandardHelpOptions = true
|
||||
)
|
||||
public class AzVersionCommand implements Callable<Integer> {
|
||||
public class AzVersionCommand extends VersionCommand {
|
||||
|
||||
@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;
|
||||
public AzVersionCommand() {
|
||||
super(ProductProfile.AZ);
|
||||
}
|
||||
}
|
||||
@@ -1,73 +1,17 @@
|
||||
package io.floci.cli.commands.az;
|
||||
|
||||
import io.floci.cli.AzGlobalOptions;
|
||||
import io.floci.cli.ProductProfile;
|
||||
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;
|
||||
import picocli.CommandLine.Command;
|
||||
|
||||
@Command(
|
||||
name = "wait",
|
||||
description = "Wait until Floci Azure is ready to accept requests",
|
||||
mixinStandardHelpOptions = true
|
||||
)
|
||||
public class AzWaitCommand implements Callable<Integer> {
|
||||
public class AzWaitCommand extends WaitCommand {
|
||||
|
||||
@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;
|
||||
}
|
||||
public AzWaitCommand() {
|
||||
super(ProductProfile.AZ);
|
||||
}
|
||||
}
|
||||
@@ -1,115 +1,17 @@
|
||||
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;
|
||||
import io.floci.cli.ProductProfile;
|
||||
import io.floci.cli.commands.config.ConfigProfileCommand;
|
||||
import picocli.CommandLine.Command;
|
||||
|
||||
@Command(
|
||||
name = "profile",
|
||||
description = "Manage Floci Azure configuration profiles",
|
||||
mixinStandardHelpOptions = true,
|
||||
subcommands = {HelpCommand.class}
|
||||
mixinStandardHelpOptions = true
|
||||
)
|
||||
public class AzConfigProfileCommand implements Callable<Integer> {
|
||||
public class AzConfigProfileCommand extends ConfigProfileCommand {
|
||||
|
||||
@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;
|
||||
}
|
||||
public AzConfigProfileCommand() {
|
||||
super(ProductProfile.AZ);
|
||||
}
|
||||
}
|
||||
@@ -1,70 +1,17 @@
|
||||
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;
|
||||
import io.floci.cli.ProductProfile;
|
||||
import io.floci.cli.commands.config.ConfigShowCommand;
|
||||
import picocli.CommandLine.Command;
|
||||
|
||||
@Command(
|
||||
name = "show",
|
||||
description = "Show the active Floci Azure configuration",
|
||||
mixinStandardHelpOptions = true
|
||||
)
|
||||
public class AzConfigShowCommand implements Callable<Integer> {
|
||||
public class AzConfigShowCommand extends ConfigShowCommand {
|
||||
|
||||
@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;
|
||||
public AzConfigShowCommand() {
|
||||
super(ProductProfile.AZ);
|
||||
}
|
||||
}
|
||||
@@ -1,91 +1,17 @@
|
||||
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;
|
||||
import io.floci.cli.ProductProfile;
|
||||
import io.floci.cli.commands.config.ConfigValidateCommand;
|
||||
import picocli.CommandLine.Command;
|
||||
|
||||
@Command(
|
||||
name = "validate",
|
||||
description = "Validate a docker-compose.yml file for Floci Azure compatibility",
|
||||
mixinStandardHelpOptions = true
|
||||
)
|
||||
public class AzConfigValidateCommand implements Callable<Integer> {
|
||||
public class AzConfigValidateCommand extends ConfigValidateCommand {
|
||||
|
||||
@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;
|
||||
public AzConfigValidateCommand() {
|
||||
super(ProductProfile.AZ, false, "Azure Functions");
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import picocli.CommandLine.*;
|
||||
|
||||
@Command(
|
||||
name = "snapshot",
|
||||
description = "Manage Floci Azure state snapshots (coming soon)",
|
||||
description = "Manage Floci Azure state snapshots",
|
||||
mixinStandardHelpOptions = true,
|
||||
subcommands = {
|
||||
AzSnapshotSaveCommand.class,
|
||||
|
||||
@@ -1,28 +1,17 @@
|
||||
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;
|
||||
import io.floci.cli.ProductProfile;
|
||||
import io.floci.cli.commands.snapshot.SnapshotDeleteCommand;
|
||||
import picocli.CommandLine.Command;
|
||||
|
||||
@Command(
|
||||
name = "delete",
|
||||
description = "Delete a Floci Azure snapshot",
|
||||
mixinStandardHelpOptions = true
|
||||
)
|
||||
public class AzSnapshotDeleteCommand implements Callable<Integer> {
|
||||
public class AzSnapshotDeleteCommand extends SnapshotDeleteCommand {
|
||||
|
||||
@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;
|
||||
public AzSnapshotDeleteCommand() {
|
||||
super(ProductProfile.AZ);
|
||||
}
|
||||
}
|
||||
@@ -1,31 +1,17 @@
|
||||
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;
|
||||
import io.floci.cli.ProductProfile;
|
||||
import io.floci.cli.commands.snapshot.SnapshotExportCommand;
|
||||
import picocli.CommandLine.Command;
|
||||
|
||||
@Command(
|
||||
name = "export",
|
||||
description = "Export a Floci Azure snapshot to a tarball file",
|
||||
mixinStandardHelpOptions = true
|
||||
)
|
||||
public class AzSnapshotExportCommand implements Callable<Integer> {
|
||||
public class AzSnapshotExportCommand extends SnapshotExportCommand {
|
||||
|
||||
@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;
|
||||
public AzSnapshotExportCommand() {
|
||||
super(ProductProfile.AZ);
|
||||
}
|
||||
}
|
||||
@@ -1,31 +1,17 @@
|
||||
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;
|
||||
import io.floci.cli.ProductProfile;
|
||||
import io.floci.cli.commands.snapshot.SnapshotImportCommand;
|
||||
import picocli.CommandLine.Command;
|
||||
|
||||
@Command(
|
||||
name = "import",
|
||||
description = "Import a Floci Azure snapshot from a tarball file",
|
||||
mixinStandardHelpOptions = true
|
||||
)
|
||||
public class AzSnapshotImportCommand implements Callable<Integer> {
|
||||
public class AzSnapshotImportCommand extends SnapshotImportCommand {
|
||||
|
||||
@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;
|
||||
public AzSnapshotImportCommand() {
|
||||
super(ProductProfile.AZ);
|
||||
}
|
||||
}
|
||||
@@ -1,34 +1,17 @@
|
||||
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;
|
||||
import io.floci.cli.ProductProfile;
|
||||
import io.floci.cli.commands.snapshot.SnapshotListCommand;
|
||||
import picocli.CommandLine.Command;
|
||||
|
||||
@Command(
|
||||
name = "list",
|
||||
description = "List available Floci Azure snapshots",
|
||||
mixinStandardHelpOptions = true
|
||||
)
|
||||
public class AzSnapshotListCommand implements Callable<Integer> {
|
||||
public class AzSnapshotListCommand extends SnapshotListCommand {
|
||||
|
||||
@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;
|
||||
public AzSnapshotListCommand() {
|
||||
super(ProductProfile.AZ);
|
||||
}
|
||||
}
|
||||
@@ -1,28 +1,17 @@
|
||||
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;
|
||||
import io.floci.cli.ProductProfile;
|
||||
import io.floci.cli.commands.snapshot.SnapshotLoadCommand;
|
||||
import picocli.CommandLine.Command;
|
||||
|
||||
@Command(
|
||||
name = "load",
|
||||
description = "Restore a saved Floci Azure snapshot",
|
||||
description = "Load a Floci Azure snapshot",
|
||||
mixinStandardHelpOptions = true
|
||||
)
|
||||
public class AzSnapshotLoadCommand implements Callable<Integer> {
|
||||
public class AzSnapshotLoadCommand extends SnapshotLoadCommand {
|
||||
|
||||
@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;
|
||||
public AzSnapshotLoadCommand() {
|
||||
super(ProductProfile.AZ);
|
||||
}
|
||||
}
|
||||
@@ -1,32 +1,17 @@
|
||||
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;
|
||||
import io.floci.cli.ProductProfile;
|
||||
import io.floci.cli.commands.snapshot.SnapshotSaveCommand;
|
||||
import picocli.CommandLine.Command;
|
||||
|
||||
@Command(
|
||||
name = "save",
|
||||
description = "Save the current Floci Azure state as a named snapshot",
|
||||
mixinStandardHelpOptions = true
|
||||
)
|
||||
public class AzSnapshotSaveCommand implements Callable<Integer> {
|
||||
public class AzSnapshotSaveCommand extends SnapshotSaveCommand {
|
||||
|
||||
@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;
|
||||
public AzSnapshotSaveCommand() {
|
||||
super(ProductProfile.AZ);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package io.floci.cli.commands.config;
|
||||
|
||||
import io.floci.cli.GlobalOptions;
|
||||
import io.floci.cli.ProductProfile;
|
||||
import io.floci.cli.config.Profile;
|
||||
import io.floci.cli.config.ProfileStore;
|
||||
import io.floci.cli.output.Ansi;
|
||||
@@ -13,14 +14,25 @@ import java.util.concurrent.Callable;
|
||||
|
||||
@Command(
|
||||
name = "profile",
|
||||
description = "Manage Floci configuration profiles",
|
||||
description = "Manage Floci AWS configuration profiles",
|
||||
mixinStandardHelpOptions = true,
|
||||
subcommands = {HelpCommand.class}
|
||||
)
|
||||
public class ConfigProfileCommand implements Callable<Integer> {
|
||||
|
||||
protected final ProductProfile profile;
|
||||
|
||||
@Mixin
|
||||
GlobalOptions global;
|
||||
protected GlobalOptions global;
|
||||
|
||||
public ConfigProfileCommand() {
|
||||
this(ProductProfile.AWS);
|
||||
}
|
||||
|
||||
protected ConfigProfileCommand(ProductProfile profile) {
|
||||
this.profile = profile;
|
||||
this.global = new GlobalOptions(profile);
|
||||
}
|
||||
|
||||
@Parameters(index = "0", description = "Action: list, show, create, delete", paramLabel = "list|show|create|delete")
|
||||
String action;
|
||||
@@ -49,7 +61,7 @@ public class ConfigProfileCommand implements Callable<Integer> {
|
||||
try {
|
||||
List<Profile> profiles = store.list();
|
||||
if (profiles.isEmpty()) {
|
||||
printer.println(Ansi.gray("No profiles found. Create one with: floci config profile create <name>"));
|
||||
printer.println(Ansi.gray("No profiles found. Create one with: " + profile.commandPrefix() + " config profile create <name>"));
|
||||
return 0;
|
||||
}
|
||||
printer.println(Ansi.bold("Profiles:"));
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package io.floci.cli.commands.config;
|
||||
|
||||
import io.floci.cli.GlobalOptions;
|
||||
import io.floci.cli.ProductProfile;
|
||||
import io.floci.cli.config.Profile;
|
||||
import io.floci.cli.config.ProfileStore;
|
||||
import io.floci.cli.output.Ansi;
|
||||
@@ -16,13 +17,24 @@ import java.util.concurrent.Callable;
|
||||
|
||||
@Command(
|
||||
name = "show",
|
||||
description = "Show the active configuration",
|
||||
description = "Show the active Floci AWS configuration",
|
||||
mixinStandardHelpOptions = true
|
||||
)
|
||||
public class ConfigShowCommand implements Callable<Integer> {
|
||||
|
||||
protected final ProductProfile profile;
|
||||
|
||||
@Mixin
|
||||
GlobalOptions global;
|
||||
protected GlobalOptions global;
|
||||
|
||||
public ConfigShowCommand() {
|
||||
this(ProductProfile.AWS);
|
||||
}
|
||||
|
||||
protected ConfigShowCommand(ProductProfile profile) {
|
||||
this.profile = profile;
|
||||
this.global = new GlobalOptions(profile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer call() {
|
||||
@@ -58,7 +70,7 @@ public class ConfigShowCommand implements Callable<Integer> {
|
||||
return 0;
|
||||
}
|
||||
|
||||
printer.println(Ansi.bold("Active Configuration"));
|
||||
printer.println(Ansi.bold("Active Configuration (" + profile.displayName() + ")"));
|
||||
printer.println("");
|
||||
printer.println(" Profile: " + active.name);
|
||||
printer.println(" Endpoint: " + (active.endpoint != null ? active.endpoint : global.endpoint));
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package io.floci.cli.commands.config;
|
||||
|
||||
import io.floci.cli.GlobalOptions;
|
||||
import io.floci.cli.ProductProfile;
|
||||
import io.floci.cli.output.Ansi;
|
||||
import io.floci.cli.output.Printer;
|
||||
import picocli.CommandLine.*;
|
||||
@@ -15,13 +16,28 @@ import java.util.regex.Pattern;
|
||||
|
||||
@Command(
|
||||
name = "validate",
|
||||
description = "Validate a docker-compose.yml file for Floci compatibility",
|
||||
description = "Validate a docker-compose.yml file for Floci AWS compatibility",
|
||||
mixinStandardHelpOptions = true
|
||||
)
|
||||
public class ConfigValidateCommand implements Callable<Integer> {
|
||||
|
||||
protected final ProductProfile profile;
|
||||
private final boolean dockerSockRequired;
|
||||
private final String dockerSockNeededFor;
|
||||
|
||||
@Mixin
|
||||
GlobalOptions global;
|
||||
protected GlobalOptions global;
|
||||
|
||||
public ConfigValidateCommand() {
|
||||
this(ProductProfile.AWS, true, "Lambda, EC2, EKS, MSK, ECR, CodeBuild");
|
||||
}
|
||||
|
||||
protected ConfigValidateCommand(ProductProfile profile, boolean dockerSockRequired, String dockerSockNeededFor) {
|
||||
this.profile = profile;
|
||||
this.dockerSockRequired = dockerSockRequired;
|
||||
this.dockerSockNeededFor = dockerSockNeededFor;
|
||||
this.global = new GlobalOptions(profile);
|
||||
}
|
||||
|
||||
@Option(names = {"--file", "-f"}, description = "Path to docker-compose file", paramLabel = "<path>")
|
||||
String file;
|
||||
@@ -50,19 +66,24 @@ public class ConfigValidateCommand implements Callable<Integer> {
|
||||
List<String> issues = new ArrayList<>();
|
||||
List<String> warnings = new ArrayList<>();
|
||||
|
||||
// Check for docker.sock mount
|
||||
// Check for docker.sock mount (an error where the product needs it for core services)
|
||||
if (!content.contains("/var/run/docker.sock")) {
|
||||
issues.add("Missing /var/run/docker.sock volume mount — required for Lambda, EC2, EKS, MSK, ECR, CodeBuild");
|
||||
(dockerSockRequired ? issues : warnings)
|
||||
.add("Missing /var/run/docker.sock volume mount — required for " + dockerSockNeededFor);
|
||||
}
|
||||
|
||||
// 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");
|
||||
int port = profile.defaultPort();
|
||||
if (!Pattern.compile(port + "\\s*:\\s*" + port).matcher(content).find()) {
|
||||
issues.add("Port mapping " + port + ":" + port + " not found — " + profile.displayName()
|
||||
+ " listens on " + port + " 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");
|
||||
// Check for the product image
|
||||
String ghcrImage = "ghcr.io/floci-io/" + profile.image().substring(profile.image().indexOf('/') + 1);
|
||||
if (!content.contains(profile.image()) && !content.contains(ghcrImage)) {
|
||||
warnings.add(profile.displayName() + " image reference not detected — ensure your service uses "
|
||||
+ profile.image() + " or " + ghcrImage);
|
||||
}
|
||||
|
||||
for (String issue : issues) {
|
||||
|
||||
@@ -1,108 +1,19 @@
|
||||
package io.floci.cli.commands.gcp;
|
||||
|
||||
import io.floci.cli.GcpGlobalOptions;
|
||||
import io.floci.cli.ProductProfile;
|
||||
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.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 picocli.CommandLine.Command;
|
||||
|
||||
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 GCP",
|
||||
mixinStandardHelpOptions = true
|
||||
)
|
||||
public class GcpDoctorCommand implements Callable<Integer> {
|
||||
public class GcpDoctorCommand extends DoctorCommand {
|
||||
|
||||
@Mixin
|
||||
GcpGlobalOptions 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;
|
||||
|
||||
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-gcp"));
|
||||
checks.add(new ImageVersionCheck("floci/floci-gcp"));
|
||||
checks.add(new ContainerRunningCheck());
|
||||
checks.add(new EndpointReachableCheck(io.floci.cli.GcpGlobalOptions.CONTROL_PREFIX));
|
||||
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 GCP 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;
|
||||
public GcpDoctorCommand() {
|
||||
super(ProductProfile.GCP, List.of());
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package io.floci.cli.commands.gcp;
|
||||
|
||||
import io.floci.cli.GcpGlobalOptions;
|
||||
import io.floci.cli.GlobalOptions;
|
||||
import io.floci.cli.ProductProfile;
|
||||
import io.floci.cli.docker.DockerClient;
|
||||
import io.floci.cli.output.Ansi;
|
||||
import io.floci.cli.output.OutputFormat;
|
||||
@@ -26,7 +27,7 @@ public class GcpEnvCommand implements Callable<Integer> {
|
||||
Set.of("gcs", "pubsub", "firestore", "datastore", "secretmanager", "iam");
|
||||
|
||||
@Mixin
|
||||
GcpGlobalOptions global;
|
||||
GlobalOptions global = new GlobalOptions(ProductProfile.GCP);
|
||||
|
||||
@Option(names = {"--service"},
|
||||
description = "Comma-separated services: gcs,pubsub,firestore,datastore,secretmanager,iam",
|
||||
|
||||
@@ -1,54 +1,17 @@
|
||||
package io.floci.cli.commands.gcp;
|
||||
|
||||
import io.floci.cli.GcpGlobalOptions;
|
||||
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;
|
||||
import io.floci.cli.ProductProfile;
|
||||
import io.floci.cli.commands.LogsCommand;
|
||||
import picocli.CommandLine.Command;
|
||||
|
||||
@Command(
|
||||
name = "logs",
|
||||
description = "Fetch logs from the Floci GCP container",
|
||||
mixinStandardHelpOptions = true
|
||||
)
|
||||
public class GcpLogsCommand implements Callable<Integer> {
|
||||
public class GcpLogsCommand extends LogsCommand {
|
||||
|
||||
@Mixin
|
||||
GcpGlobalOptions 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 gcp 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;
|
||||
}
|
||||
public GcpLogsCommand() {
|
||||
super(ProductProfile.GCP);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,40 +1,17 @@
|
||||
package io.floci.cli.commands.gcp;
|
||||
|
||||
import io.floci.cli.GcpGlobalOptions;
|
||||
import io.floci.cli.output.Printer;
|
||||
import picocli.CommandLine.*;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
import io.floci.cli.ProductProfile;
|
||||
import io.floci.cli.commands.RestartCommand;
|
||||
import picocli.CommandLine.Command;
|
||||
|
||||
@Command(
|
||||
name = "restart",
|
||||
description = "Stop and restart the Floci GCP container",
|
||||
mixinStandardHelpOptions = true
|
||||
)
|
||||
public class GcpRestartCommand implements Callable<Integer> {
|
||||
public class GcpRestartCommand extends RestartCommand {
|
||||
|
||||
@Mixin
|
||||
GcpGlobalOptions global;
|
||||
|
||||
@Override
|
||||
public Integer call() {
|
||||
Printer printer = global.printer();
|
||||
|
||||
GcpStopCommand stop = new GcpStopCommand();
|
||||
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(); }
|
||||
|
||||
GcpStartCommand start = new GcpStartCommand();
|
||||
start.global = global;
|
||||
start.port = 4588;
|
||||
start.pull = "missing";
|
||||
start.image = "floci/floci-gcp:latest";
|
||||
start.detach = false;
|
||||
return start.call();
|
||||
public GcpRestartCommand() {
|
||||
super(ProductProfile.GCP);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,55 +1,17 @@
|
||||
package io.floci.cli.commands.gcp;
|
||||
|
||||
import io.floci.cli.GcpGlobalOptions;
|
||||
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;
|
||||
import io.floci.cli.ProductProfile;
|
||||
import io.floci.cli.commands.ServicesCommand;
|
||||
import picocli.CommandLine.Command;
|
||||
|
||||
@Command(
|
||||
name = "services",
|
||||
description = "List services available in the running Floci GCP instance",
|
||||
mixinStandardHelpOptions = true
|
||||
)
|
||||
public class GcpServicesCommand implements Callable<Integer> {
|
||||
public class GcpServicesCommand extends ServicesCommand {
|
||||
|
||||
@Mixin
|
||||
GcpGlobalOptions global;
|
||||
|
||||
@Override
|
||||
public Integer call() {
|
||||
Printer printer = global.printer();
|
||||
FlociHttpClient client = new FlociHttpClient(global.endpoint, GcpGlobalOptions.CONTROL_PREFIX);
|
||||
|
||||
List<String> services;
|
||||
try {
|
||||
var health = client.health();
|
||||
services = Arrays.asList(health.services());
|
||||
} catch (Exception e) {
|
||||
printer.error("Could not reach Floci GCP at " + global.endpoint + ".\nIs Floci GCP running? Try 'floci gcp start'.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (printer.format() != OutputFormat.text) {
|
||||
printer.structured(Map.of("services", services, "count", services.size()));
|
||||
return 0;
|
||||
}
|
||||
|
||||
printer.println(Ansi.bold("Floci GCP 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;
|
||||
public GcpServicesCommand() {
|
||||
super(ProductProfile.GCP);
|
||||
}
|
||||
}
|
||||
@@ -1,113 +1,17 @@
|
||||
package io.floci.cli.commands.gcp;
|
||||
|
||||
import io.floci.cli.GcpGlobalOptions;
|
||||
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;
|
||||
import io.floci.cli.ProductProfile;
|
||||
import io.floci.cli.commands.StartCommand;
|
||||
import picocli.CommandLine.Command;
|
||||
|
||||
@Command(
|
||||
name = "start",
|
||||
description = "Start the Floci GCP emulator container",
|
||||
mixinStandardHelpOptions = true
|
||||
)
|
||||
public class GcpStartCommand implements Callable<Integer> {
|
||||
public class GcpStartCommand extends StartCommand {
|
||||
|
||||
@Mixin
|
||||
GcpGlobalOptions global;
|
||||
|
||||
@Option(names = {"--port"}, description = "Host port to bind (default: 4588)", defaultValue = "4588", 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-gcp:latest)", defaultValue = "floci/floci-gcp: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 gcp 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 gcp 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 + ":4588"));
|
||||
args.addAll(DockerClient.dockerSocketRunArgs());
|
||||
if (persistDir != null) {
|
||||
args.addAll(List.of("-v", persistDir + ":/app/data"));
|
||||
// The server defaults to in-memory storage; enable persistent mode so
|
||||
// state is actually written to the mounted directory and survives restarts.
|
||||
args.addAll(List.of("-e", "FLOCI_GCP_STORAGE_MODE=persistent"));
|
||||
}
|
||||
if (services != null && !services.isBlank()) {
|
||||
args.addAll(List.of("-e", "FLOCI_GCP_SERVICES=" + services));
|
||||
}
|
||||
args.add(image);
|
||||
|
||||
try {
|
||||
printer.println("Starting " + Ansi.gold("Floci GCP") + " 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 gcp wait' to poll for readiness."));
|
||||
return 0;
|
||||
}
|
||||
|
||||
global.endpoint = "http://localhost:" + port;
|
||||
|
||||
printer.println(Ansi.gray("Waiting for Floci GCP to be ready..."));
|
||||
GcpWaitCommand wait = new GcpWaitCommand();
|
||||
wait.global = global;
|
||||
wait.timeout = "30s";
|
||||
return wait.call();
|
||||
public GcpStartCommand() {
|
||||
super(ProductProfile.GCP);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,98 +1,17 @@
|
||||
package io.floci.cli.commands.gcp;
|
||||
|
||||
import io.floci.cli.GcpGlobalOptions;
|
||||
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;
|
||||
import io.floci.cli.ProductProfile;
|
||||
import io.floci.cli.commands.StatusCommand;
|
||||
import picocli.CommandLine.Command;
|
||||
|
||||
@Command(
|
||||
name = "status",
|
||||
description = "Show Floci GCP container and server status",
|
||||
mixinStandardHelpOptions = true
|
||||
)
|
||||
public class GcpStatusCommand implements Callable<Integer> {
|
||||
public class GcpStatusCommand extends StatusCommand {
|
||||
|
||||
@Mixin
|
||||
GcpGlobalOptions 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, GcpGlobalOptions.CONTROL_PREFIX);
|
||||
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 GCP 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 gcp start' to launch Floci GCP."));
|
||||
}
|
||||
|
||||
return 0;
|
||||
public GcpStatusCommand() {
|
||||
super(ProductProfile.GCP);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,73 +1,17 @@
|
||||
package io.floci.cli.commands.gcp;
|
||||
|
||||
import io.floci.cli.GcpGlobalOptions;
|
||||
import io.floci.cli.docker.DockerClient;
|
||||
import io.floci.cli.docker.DockerException;
|
||||
import io.floci.cli.output.Ansi;
|
||||
import io.floci.cli.output.Printer;
|
||||
import picocli.CommandLine.*;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
import io.floci.cli.ProductProfile;
|
||||
import io.floci.cli.commands.StopCommand;
|
||||
import picocli.CommandLine.Command;
|
||||
|
||||
@Command(
|
||||
name = "stop",
|
||||
description = "Stop the Floci GCP container",
|
||||
mixinStandardHelpOptions = true
|
||||
)
|
||||
public class GcpStopCommand implements Callable<Integer> {
|
||||
public class GcpStopCommand extends StopCommand {
|
||||
|
||||
@Mixin
|
||||
GcpGlobalOptions 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 gcp 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 GCP") + " container '" + global.container + "'...");
|
||||
docker.stopContainer(global.container, timeout);
|
||||
printer.println(Ansi.green("Stopped."));
|
||||
} catch (DockerException e) {
|
||||
printer.error("Failed to stop container: " + e.getMessage());
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (remove) {
|
||||
try {
|
||||
docker.removeContainer(global.container);
|
||||
printer.println("Container removed.");
|
||||
} catch (DockerException e) {
|
||||
printer.error("Failed to remove container: " + e.getMessage());
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
public GcpStopCommand() {
|
||||
super(ProductProfile.GCP);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,72 +1,17 @@
|
||||
package io.floci.cli.commands.gcp;
|
||||
|
||||
import io.floci.cli.GcpGlobalOptions;
|
||||
import io.floci.cli.ProductProfile;
|
||||
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;
|
||||
import picocli.CommandLine.Command;
|
||||
|
||||
@Command(
|
||||
name = "version",
|
||||
description = "Show CLI version, connected Floci GCP server version, and image digest",
|
||||
mixinStandardHelpOptions = true
|
||||
)
|
||||
public class GcpVersionCommand implements Callable<Integer> {
|
||||
public class GcpVersionCommand extends VersionCommand {
|
||||
|
||||
@Mixin
|
||||
GcpGlobalOptions 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, GcpGlobalOptions.CONTROL_PREFIX);
|
||||
try {
|
||||
var info = client.info();
|
||||
serverVersion = info.version();
|
||||
serverEdition = info.edition();
|
||||
} catch (Exception ignored) {}
|
||||
|
||||
try {
|
||||
imageDigest = docker.imageDigest("floci/floci-gcp").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;
|
||||
public GcpVersionCommand() {
|
||||
super(ProductProfile.GCP);
|
||||
}
|
||||
}
|
||||
@@ -1,73 +1,17 @@
|
||||
package io.floci.cli.commands.gcp;
|
||||
|
||||
import io.floci.cli.GcpGlobalOptions;
|
||||
import io.floci.cli.ProductProfile;
|
||||
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;
|
||||
import picocli.CommandLine.Command;
|
||||
|
||||
@Command(
|
||||
name = "wait",
|
||||
description = "Wait until Floci GCP is ready to accept requests",
|
||||
mixinStandardHelpOptions = true
|
||||
)
|
||||
public class GcpWaitCommand implements Callable<Integer> {
|
||||
public class GcpWaitCommand extends WaitCommand {
|
||||
|
||||
@Mixin
|
||||
GcpGlobalOptions 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, GcpGlobalOptions.CONTROL_PREFIX);
|
||||
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 GCP 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 GCP after " + timeout + ".\nIs the container running? Try 'floci gcp status'.");
|
||||
return 1;
|
||||
public GcpWaitCommand() {
|
||||
super(ProductProfile.GCP);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,115 +1,17 @@
|
||||
package io.floci.cli.commands.gcp.config;
|
||||
|
||||
import io.floci.cli.GcpGlobalOptions;
|
||||
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;
|
||||
import io.floci.cli.ProductProfile;
|
||||
import io.floci.cli.commands.config.ConfigProfileCommand;
|
||||
import picocli.CommandLine.Command;
|
||||
|
||||
@Command(
|
||||
name = "profile",
|
||||
description = "Manage Floci GCP configuration profiles",
|
||||
mixinStandardHelpOptions = true,
|
||||
subcommands = {HelpCommand.class}
|
||||
mixinStandardHelpOptions = true
|
||||
)
|
||||
public class GcpConfigProfileCommand implements Callable<Integer> {
|
||||
public class GcpConfigProfileCommand extends ConfigProfileCommand {
|
||||
|
||||
@Mixin
|
||||
GcpGlobalOptions 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 gcp 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;
|
||||
}
|
||||
public GcpConfigProfileCommand() {
|
||||
super(ProductProfile.GCP);
|
||||
}
|
||||
}
|
||||
@@ -1,70 +1,17 @@
|
||||
package io.floci.cli.commands.gcp.config;
|
||||
|
||||
import io.floci.cli.GcpGlobalOptions;
|
||||
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;
|
||||
import io.floci.cli.ProductProfile;
|
||||
import io.floci.cli.commands.config.ConfigShowCommand;
|
||||
import picocli.CommandLine.Command;
|
||||
|
||||
@Command(
|
||||
name = "show",
|
||||
description = "Show the active Floci GCP configuration",
|
||||
mixinStandardHelpOptions = true
|
||||
)
|
||||
public class GcpConfigShowCommand implements Callable<Integer> {
|
||||
public class GcpConfigShowCommand extends ConfigShowCommand {
|
||||
|
||||
@Mixin
|
||||
GcpGlobalOptions 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 GCP)"));
|
||||
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;
|
||||
public GcpConfigShowCommand() {
|
||||
super(ProductProfile.GCP);
|
||||
}
|
||||
}
|
||||
@@ -1,91 +1,17 @@
|
||||
package io.floci.cli.commands.gcp.config;
|
||||
|
||||
import io.floci.cli.GcpGlobalOptions;
|
||||
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;
|
||||
import io.floci.cli.ProductProfile;
|
||||
import io.floci.cli.commands.config.ConfigValidateCommand;
|
||||
import picocli.CommandLine.Command;
|
||||
|
||||
@Command(
|
||||
name = "validate",
|
||||
description = "Validate a docker-compose.yml file for Floci GCP compatibility",
|
||||
mixinStandardHelpOptions = true
|
||||
)
|
||||
public class GcpConfigValidateCommand implements Callable<Integer> {
|
||||
public class GcpConfigValidateCommand extends ConfigValidateCommand {
|
||||
|
||||
@Mixin
|
||||
GcpGlobalOptions 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 Kafka/Redpanda support");
|
||||
}
|
||||
|
||||
if (!Pattern.compile("4588\\s*:\\s*4588").matcher(content).find()) {
|
||||
issues.add("Port mapping 4588:4588 not found — Floci GCP listens on 4588 by default");
|
||||
}
|
||||
|
||||
if (!content.contains("floci/floci-gcp") && !content.contains("ghcr.io/floci-io/floci-gcp")) {
|
||||
warnings.add("Floci GCP image reference not detected — ensure your service uses floci/floci-gcp");
|
||||
}
|
||||
|
||||
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;
|
||||
public GcpConfigValidateCommand() {
|
||||
super(ProductProfile.GCP, false, "Kafka/Redpanda support");
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import picocli.CommandLine.*;
|
||||
|
||||
@Command(
|
||||
name = "snapshot",
|
||||
description = "Manage Floci GCP state snapshots (coming soon)",
|
||||
description = "Manage Floci GCP state snapshots",
|
||||
mixinStandardHelpOptions = true,
|
||||
subcommands = {
|
||||
GcpSnapshotSaveCommand.class,
|
||||
|
||||
@@ -1,28 +1,17 @@
|
||||
package io.floci.cli.commands.gcp.snapshot;
|
||||
|
||||
import io.floci.cli.GcpGlobalOptions;
|
||||
import io.floci.cli.output.Ansi;
|
||||
import picocli.CommandLine.*;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
import io.floci.cli.ProductProfile;
|
||||
import io.floci.cli.commands.snapshot.SnapshotDeleteCommand;
|
||||
import picocli.CommandLine.Command;
|
||||
|
||||
@Command(
|
||||
name = "delete",
|
||||
description = "Delete a Floci GCP snapshot",
|
||||
mixinStandardHelpOptions = true
|
||||
)
|
||||
public class GcpSnapshotDeleteCommand implements Callable<Integer> {
|
||||
public class GcpSnapshotDeleteCommand extends SnapshotDeleteCommand {
|
||||
|
||||
@Mixin
|
||||
GcpGlobalOptions 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 GCP.") +
|
||||
"\nTrack progress: https://github.com/floci-io/floci-gcp/issues");
|
||||
return 0;
|
||||
public GcpSnapshotDeleteCommand() {
|
||||
super(ProductProfile.GCP);
|
||||
}
|
||||
}
|
||||
@@ -1,31 +1,17 @@
|
||||
package io.floci.cli.commands.gcp.snapshot;
|
||||
|
||||
import io.floci.cli.GcpGlobalOptions;
|
||||
import io.floci.cli.output.Ansi;
|
||||
import picocli.CommandLine.*;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
import io.floci.cli.ProductProfile;
|
||||
import io.floci.cli.commands.snapshot.SnapshotExportCommand;
|
||||
import picocli.CommandLine.Command;
|
||||
|
||||
@Command(
|
||||
name = "export",
|
||||
description = "Export a Floci GCP snapshot to a tarball file",
|
||||
mixinStandardHelpOptions = true
|
||||
)
|
||||
public class GcpSnapshotExportCommand implements Callable<Integer> {
|
||||
public class GcpSnapshotExportCommand extends SnapshotExportCommand {
|
||||
|
||||
@Mixin
|
||||
GcpGlobalOptions 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 GCP.") +
|
||||
"\nTrack progress: https://github.com/floci-io/floci-gcp/issues");
|
||||
return 0;
|
||||
public GcpSnapshotExportCommand() {
|
||||
super(ProductProfile.GCP);
|
||||
}
|
||||
}
|
||||
@@ -1,31 +1,17 @@
|
||||
package io.floci.cli.commands.gcp.snapshot;
|
||||
|
||||
import io.floci.cli.GcpGlobalOptions;
|
||||
import io.floci.cli.output.Ansi;
|
||||
import picocli.CommandLine.*;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
import io.floci.cli.ProductProfile;
|
||||
import io.floci.cli.commands.snapshot.SnapshotImportCommand;
|
||||
import picocli.CommandLine.Command;
|
||||
|
||||
@Command(
|
||||
name = "import",
|
||||
description = "Import a Floci GCP snapshot from a tarball file",
|
||||
mixinStandardHelpOptions = true
|
||||
)
|
||||
public class GcpSnapshotImportCommand implements Callable<Integer> {
|
||||
public class GcpSnapshotImportCommand extends SnapshotImportCommand {
|
||||
|
||||
@Mixin
|
||||
GcpGlobalOptions global;
|
||||
|
||||
@Parameters(index = "0", description = "Snapshot name", paramLabel = "<name>")
|
||||
String name;
|
||||
|
||||
@Option(names = {"--file", "-f"}, description = "Source file path", required = true, paramLabel = "<path>")
|
||||
String inputFile;
|
||||
|
||||
@Override
|
||||
public Integer call() {
|
||||
global.printer().println(Ansi.yellow("Snapshots are not yet available for Floci GCP.") +
|
||||
"\nTrack progress: https://github.com/floci-io/floci-gcp/issues");
|
||||
return 0;
|
||||
public GcpSnapshotImportCommand() {
|
||||
super(ProductProfile.GCP);
|
||||
}
|
||||
}
|
||||
@@ -1,34 +1,17 @@
|
||||
package io.floci.cli.commands.gcp.snapshot;
|
||||
|
||||
import io.floci.cli.GcpGlobalOptions;
|
||||
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;
|
||||
import io.floci.cli.ProductProfile;
|
||||
import io.floci.cli.commands.snapshot.SnapshotListCommand;
|
||||
import picocli.CommandLine.Command;
|
||||
|
||||
@Command(
|
||||
name = "list",
|
||||
description = "List available Floci GCP snapshots",
|
||||
mixinStandardHelpOptions = true
|
||||
)
|
||||
public class GcpSnapshotListCommand implements Callable<Integer> {
|
||||
public class GcpSnapshotListCommand extends SnapshotListCommand {
|
||||
|
||||
@Mixin
|
||||
GcpGlobalOptions 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 GCP is coming — https://github.com/floci-io/floci-gcp/issues)");
|
||||
return 0;
|
||||
public GcpSnapshotListCommand() {
|
||||
super(ProductProfile.GCP);
|
||||
}
|
||||
}
|
||||
@@ -1,28 +1,17 @@
|
||||
package io.floci.cli.commands.gcp.snapshot;
|
||||
|
||||
import io.floci.cli.GcpGlobalOptions;
|
||||
import io.floci.cli.output.Ansi;
|
||||
import picocli.CommandLine.*;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
import io.floci.cli.ProductProfile;
|
||||
import io.floci.cli.commands.snapshot.SnapshotLoadCommand;
|
||||
import picocli.CommandLine.Command;
|
||||
|
||||
@Command(
|
||||
name = "load",
|
||||
description = "Load a Floci GCP snapshot",
|
||||
mixinStandardHelpOptions = true
|
||||
)
|
||||
public class GcpSnapshotLoadCommand implements Callable<Integer> {
|
||||
public class GcpSnapshotLoadCommand extends SnapshotLoadCommand {
|
||||
|
||||
@Mixin
|
||||
GcpGlobalOptions 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 GCP.") +
|
||||
"\nTrack progress: https://github.com/floci-io/floci-gcp/issues");
|
||||
return 0;
|
||||
public GcpSnapshotLoadCommand() {
|
||||
super(ProductProfile.GCP);
|
||||
}
|
||||
}
|
||||
@@ -1,31 +1,17 @@
|
||||
package io.floci.cli.commands.gcp.snapshot;
|
||||
|
||||
import io.floci.cli.GcpGlobalOptions;
|
||||
import io.floci.cli.output.Ansi;
|
||||
import picocli.CommandLine.*;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
import io.floci.cli.ProductProfile;
|
||||
import io.floci.cli.commands.snapshot.SnapshotSaveCommand;
|
||||
import picocli.CommandLine.Command;
|
||||
|
||||
@Command(
|
||||
name = "save",
|
||||
description = "Save the current Floci GCP state as a named snapshot",
|
||||
mixinStandardHelpOptions = true
|
||||
)
|
||||
public class GcpSnapshotSaveCommand implements Callable<Integer> {
|
||||
public class GcpSnapshotSaveCommand extends SnapshotSaveCommand {
|
||||
|
||||
@Mixin
|
||||
GcpGlobalOptions 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 GCP.") +
|
||||
"\nTrack progress: https://github.com/floci-io/floci-gcp/issues");
|
||||
return 0;
|
||||
public GcpSnapshotSaveCommand() {
|
||||
super(ProductProfile.GCP);
|
||||
}
|
||||
}
|
||||
@@ -1,108 +1,19 @@
|
||||
package io.floci.cli.commands.oci;
|
||||
|
||||
import io.floci.cli.OciGlobalOptions;
|
||||
import io.floci.cli.ProductProfile;
|
||||
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.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 picocli.CommandLine.Command;
|
||||
|
||||
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 OCI",
|
||||
mixinStandardHelpOptions = true
|
||||
)
|
||||
public class OciDoctorCommand implements Callable<Integer> {
|
||||
public class OciDoctorCommand extends DoctorCommand {
|
||||
|
||||
@Mixin
|
||||
OciGlobalOptions 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;
|
||||
|
||||
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-oci"));
|
||||
checks.add(new ImageVersionCheck("floci/floci-oci"));
|
||||
checks.add(new ContainerRunningCheck());
|
||||
checks.add(new EndpointReachableCheck(io.floci.cli.OciGlobalOptions.CONTROL_PREFIX));
|
||||
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 OCI 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;
|
||||
public OciDoctorCommand() {
|
||||
super(ProductProfile.OCI, List.of());
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package io.floci.cli.commands.oci;
|
||||
|
||||
import io.floci.cli.OciGlobalOptions;
|
||||
import io.floci.cli.GlobalOptions;
|
||||
import io.floci.cli.ProductProfile;
|
||||
import io.floci.cli.docker.DockerClient;
|
||||
import io.floci.cli.output.Ansi;
|
||||
import io.floci.cli.output.OutputFormat;
|
||||
@@ -20,7 +21,7 @@ import java.util.concurrent.Callable;
|
||||
public class OciEnvCommand implements Callable<Integer> {
|
||||
|
||||
@Mixin
|
||||
OciGlobalOptions global;
|
||||
GlobalOptions global = new GlobalOptions(ProductProfile.OCI);
|
||||
|
||||
@Option(names = {"--shell"},
|
||||
description = "Shell format: bash, fish, powershell (default: bash)",
|
||||
|
||||
@@ -1,54 +1,17 @@
|
||||
package io.floci.cli.commands.oci;
|
||||
|
||||
import io.floci.cli.OciGlobalOptions;
|
||||
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;
|
||||
import io.floci.cli.ProductProfile;
|
||||
import io.floci.cli.commands.LogsCommand;
|
||||
import picocli.CommandLine.Command;
|
||||
|
||||
@Command(
|
||||
name = "logs",
|
||||
description = "Fetch logs from the Floci OCI container",
|
||||
mixinStandardHelpOptions = true
|
||||
)
|
||||
public class OciLogsCommand implements Callable<Integer> {
|
||||
public class OciLogsCommand extends LogsCommand {
|
||||
|
||||
@Mixin
|
||||
OciGlobalOptions 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 oci 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;
|
||||
}
|
||||
public OciLogsCommand() {
|
||||
super(ProductProfile.OCI);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,40 +1,17 @@
|
||||
package io.floci.cli.commands.oci;
|
||||
|
||||
import io.floci.cli.OciGlobalOptions;
|
||||
import io.floci.cli.output.Printer;
|
||||
import picocli.CommandLine.*;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
import io.floci.cli.ProductProfile;
|
||||
import io.floci.cli.commands.RestartCommand;
|
||||
import picocli.CommandLine.Command;
|
||||
|
||||
@Command(
|
||||
name = "restart",
|
||||
description = "Stop and restart the Floci OCI container",
|
||||
mixinStandardHelpOptions = true
|
||||
)
|
||||
public class OciRestartCommand implements Callable<Integer> {
|
||||
public class OciRestartCommand extends RestartCommand {
|
||||
|
||||
@Mixin
|
||||
OciGlobalOptions global;
|
||||
|
||||
@Override
|
||||
public Integer call() {
|
||||
Printer printer = global.printer();
|
||||
|
||||
OciStopCommand stop = new OciStopCommand();
|
||||
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(); }
|
||||
|
||||
OciStartCommand start = new OciStartCommand();
|
||||
start.global = global;
|
||||
start.port = 4599;
|
||||
start.pull = "missing";
|
||||
start.image = "floci/floci-oci:latest";
|
||||
start.detach = false;
|
||||
return start.call();
|
||||
public OciRestartCommand() {
|
||||
super(ProductProfile.OCI);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,59 +1,17 @@
|
||||
package io.floci.cli.commands.oci;
|
||||
|
||||
import io.floci.cli.OciGlobalOptions;
|
||||
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.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.Callable;
|
||||
import io.floci.cli.ProductProfile;
|
||||
import io.floci.cli.commands.ServicesCommand;
|
||||
import picocli.CommandLine.Command;
|
||||
|
||||
@Command(
|
||||
name = "services",
|
||||
description = "List services available in the running Floci OCI instance",
|
||||
mixinStandardHelpOptions = true
|
||||
)
|
||||
public class OciServicesCommand implements Callable<Integer> {
|
||||
public class OciServicesCommand extends ServicesCommand {
|
||||
|
||||
@Mixin
|
||||
OciGlobalOptions global;
|
||||
|
||||
@Override
|
||||
public Integer call() {
|
||||
Printer printer = global.printer();
|
||||
// Resolve the endpoint from the container's port mapping, like status/wait/env do,
|
||||
// so a container started with --port <n> is still found without --endpoint.
|
||||
String effectiveEndpoint = global.resolvedEndpoint(new DockerClient());
|
||||
FlociHttpClient client = new FlociHttpClient(effectiveEndpoint, OciGlobalOptions.CONTROL_PREFIX);
|
||||
|
||||
List<String> services;
|
||||
try {
|
||||
var health = client.health();
|
||||
services = Arrays.asList(health.services());
|
||||
} catch (Exception e) {
|
||||
printer.error("Could not reach Floci OCI at " + effectiveEndpoint + ".\nIs Floci OCI running? Try 'floci oci start'.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (printer.format() != OutputFormat.text) {
|
||||
printer.structured(Map.of("services", services, "count", services.size()));
|
||||
return 0;
|
||||
}
|
||||
|
||||
printer.println(Ansi.bold("Floci OCI 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;
|
||||
public OciServicesCommand() {
|
||||
super(ProductProfile.OCI);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package io.floci.cli.commands.oci;
|
||||
|
||||
import io.floci.cli.OciGlobalOptions;
|
||||
import io.floci.cli.GlobalOptions;
|
||||
import io.floci.cli.ProductProfile;
|
||||
import io.floci.cli.output.Ansi;
|
||||
import io.floci.cli.output.OutputFormat;
|
||||
import io.floci.cli.output.Printer;
|
||||
@@ -36,7 +37,7 @@ public class OciSetupCommand implements Callable<Integer> {
|
||||
static final String KEY_FILE_NAME = "floci_key.pem";
|
||||
|
||||
@Mixin
|
||||
OciGlobalOptions global;
|
||||
GlobalOptions global = new GlobalOptions(ProductProfile.OCI);
|
||||
|
||||
@Option(names = {"--profile-name"},
|
||||
description = "Profile section name to write in ~/.oci/config (default: FLOCI)",
|
||||
|
||||
@@ -1,113 +1,17 @@
|
||||
package io.floci.cli.commands.oci;
|
||||
|
||||
import io.floci.cli.OciGlobalOptions;
|
||||
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;
|
||||
import io.floci.cli.ProductProfile;
|
||||
import io.floci.cli.commands.StartCommand;
|
||||
import picocli.CommandLine.Command;
|
||||
|
||||
@Command(
|
||||
name = "start",
|
||||
description = "Start the Floci OCI emulator container",
|
||||
mixinStandardHelpOptions = true
|
||||
)
|
||||
public class OciStartCommand implements Callable<Integer> {
|
||||
public class OciStartCommand extends StartCommand {
|
||||
|
||||
@Mixin
|
||||
OciGlobalOptions global;
|
||||
|
||||
@Option(names = {"--port"}, description = "Host port to bind (default: 4599)", defaultValue = "4599", 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-oci:latest)", defaultValue = "floci/floci-oci: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 oci 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 oci 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 + ":4599"));
|
||||
args.addAll(DockerClient.dockerSocketRunArgs());
|
||||
if (persistDir != null) {
|
||||
args.addAll(List.of("-v", persistDir + ":/app/data"));
|
||||
// The server defaults to in-memory storage; enable persistent mode so
|
||||
// state is actually written to the mounted directory and survives restarts.
|
||||
args.addAll(List.of("-e", "FLOCI_OCI_STORAGE_MODE=persistent"));
|
||||
}
|
||||
if (services != null && !services.isBlank()) {
|
||||
args.addAll(List.of("-e", "FLOCI_OCI_SERVICES=" + services));
|
||||
}
|
||||
args.add(image);
|
||||
|
||||
try {
|
||||
printer.println("Starting " + Ansi.gold("Floci OCI") + " 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 oci wait' to poll for readiness."));
|
||||
return 0;
|
||||
}
|
||||
|
||||
global.endpoint = "http://localhost:" + port;
|
||||
|
||||
printer.println(Ansi.gray("Waiting for Floci OCI to be ready..."));
|
||||
OciWaitCommand wait = new OciWaitCommand();
|
||||
wait.global = global;
|
||||
wait.timeout = "30s";
|
||||
return wait.call();
|
||||
public OciStartCommand() {
|
||||
super(ProductProfile.OCI);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,98 +1,17 @@
|
||||
package io.floci.cli.commands.oci;
|
||||
|
||||
import io.floci.cli.OciGlobalOptions;
|
||||
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;
|
||||
import io.floci.cli.ProductProfile;
|
||||
import io.floci.cli.commands.StatusCommand;
|
||||
import picocli.CommandLine.Command;
|
||||
|
||||
@Command(
|
||||
name = "status",
|
||||
description = "Show Floci OCI container and server status",
|
||||
mixinStandardHelpOptions = true
|
||||
)
|
||||
public class OciStatusCommand implements Callable<Integer> {
|
||||
public class OciStatusCommand extends StatusCommand {
|
||||
|
||||
@Mixin
|
||||
OciGlobalOptions 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, OciGlobalOptions.CONTROL_PREFIX);
|
||||
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 OCI 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 oci start' to launch Floci OCI."));
|
||||
}
|
||||
|
||||
return 0;
|
||||
public OciStatusCommand() {
|
||||
super(ProductProfile.OCI);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,73 +1,17 @@
|
||||
package io.floci.cli.commands.oci;
|
||||
|
||||
import io.floci.cli.OciGlobalOptions;
|
||||
import io.floci.cli.docker.DockerClient;
|
||||
import io.floci.cli.docker.DockerException;
|
||||
import io.floci.cli.output.Ansi;
|
||||
import io.floci.cli.output.Printer;
|
||||
import picocli.CommandLine.*;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
import io.floci.cli.ProductProfile;
|
||||
import io.floci.cli.commands.StopCommand;
|
||||
import picocli.CommandLine.Command;
|
||||
|
||||
@Command(
|
||||
name = "stop",
|
||||
description = "Stop the Floci OCI container",
|
||||
mixinStandardHelpOptions = true
|
||||
)
|
||||
public class OciStopCommand implements Callable<Integer> {
|
||||
public class OciStopCommand extends StopCommand {
|
||||
|
||||
@Mixin
|
||||
OciGlobalOptions 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 oci 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 OCI") + " container '" + global.container + "'...");
|
||||
docker.stopContainer(global.container, timeout);
|
||||
printer.println(Ansi.green("Stopped."));
|
||||
} catch (DockerException e) {
|
||||
printer.error("Failed to stop container: " + e.getMessage());
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (remove) {
|
||||
try {
|
||||
docker.removeContainer(global.container);
|
||||
printer.println("Container removed.");
|
||||
} catch (DockerException e) {
|
||||
printer.error("Failed to remove container: " + e.getMessage());
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
public OciStopCommand() {
|
||||
super(ProductProfile.OCI);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,72 +1,17 @@
|
||||
package io.floci.cli.commands.oci;
|
||||
|
||||
import io.floci.cli.OciGlobalOptions;
|
||||
import io.floci.cli.ProductProfile;
|
||||
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;
|
||||
import picocli.CommandLine.Command;
|
||||
|
||||
@Command(
|
||||
name = "version",
|
||||
description = "Show CLI version, connected Floci OCI server version, and image digest",
|
||||
mixinStandardHelpOptions = true
|
||||
)
|
||||
public class OciVersionCommand implements Callable<Integer> {
|
||||
public class OciVersionCommand extends VersionCommand {
|
||||
|
||||
@Mixin
|
||||
OciGlobalOptions 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, OciGlobalOptions.CONTROL_PREFIX);
|
||||
try {
|
||||
var info = client.info();
|
||||
serverVersion = info.version();
|
||||
serverEdition = info.edition();
|
||||
} catch (Exception ignored) {}
|
||||
|
||||
try {
|
||||
imageDigest = docker.imageDigest("floci/floci-oci").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;
|
||||
public OciVersionCommand() {
|
||||
super(ProductProfile.OCI);
|
||||
}
|
||||
}
|
||||
@@ -1,73 +1,17 @@
|
||||
package io.floci.cli.commands.oci;
|
||||
|
||||
import io.floci.cli.OciGlobalOptions;
|
||||
import io.floci.cli.ProductProfile;
|
||||
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;
|
||||
import picocli.CommandLine.Command;
|
||||
|
||||
@Command(
|
||||
name = "wait",
|
||||
description = "Wait until Floci OCI is ready to accept requests",
|
||||
mixinStandardHelpOptions = true
|
||||
)
|
||||
public class OciWaitCommand implements Callable<Integer> {
|
||||
public class OciWaitCommand extends WaitCommand {
|
||||
|
||||
@Mixin
|
||||
OciGlobalOptions 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, OciGlobalOptions.CONTROL_PREFIX);
|
||||
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 OCI 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 OCI after " + timeout + ".\nIs the container running? Try 'floci oci status'.");
|
||||
return 1;
|
||||
public OciWaitCommand() {
|
||||
super(ProductProfile.OCI);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,115 +1,17 @@
|
||||
package io.floci.cli.commands.oci.config;
|
||||
|
||||
import io.floci.cli.OciGlobalOptions;
|
||||
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;
|
||||
import io.floci.cli.ProductProfile;
|
||||
import io.floci.cli.commands.config.ConfigProfileCommand;
|
||||
import picocli.CommandLine.Command;
|
||||
|
||||
@Command(
|
||||
name = "profile",
|
||||
description = "Manage Floci OCI configuration profiles",
|
||||
mixinStandardHelpOptions = true,
|
||||
subcommands = {HelpCommand.class}
|
||||
mixinStandardHelpOptions = true
|
||||
)
|
||||
public class OciConfigProfileCommand implements Callable<Integer> {
|
||||
public class OciConfigProfileCommand extends ConfigProfileCommand {
|
||||
|
||||
@Mixin
|
||||
OciGlobalOptions 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 oci 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;
|
||||
}
|
||||
public OciConfigProfileCommand() {
|
||||
super(ProductProfile.OCI);
|
||||
}
|
||||
}
|
||||
@@ -1,70 +1,17 @@
|
||||
package io.floci.cli.commands.oci.config;
|
||||
|
||||
import io.floci.cli.OciGlobalOptions;
|
||||
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;
|
||||
import io.floci.cli.ProductProfile;
|
||||
import io.floci.cli.commands.config.ConfigShowCommand;
|
||||
import picocli.CommandLine.Command;
|
||||
|
||||
@Command(
|
||||
name = "show",
|
||||
description = "Show the active Floci OCI configuration",
|
||||
mixinStandardHelpOptions = true
|
||||
)
|
||||
public class OciConfigShowCommand implements Callable<Integer> {
|
||||
public class OciConfigShowCommand extends ConfigShowCommand {
|
||||
|
||||
@Mixin
|
||||
OciGlobalOptions 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 OCI)"));
|
||||
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;
|
||||
public OciConfigShowCommand() {
|
||||
super(ProductProfile.OCI);
|
||||
}
|
||||
}
|
||||
@@ -1,91 +1,17 @@
|
||||
package io.floci.cli.commands.oci.config;
|
||||
|
||||
import io.floci.cli.OciGlobalOptions;
|
||||
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;
|
||||
import io.floci.cli.ProductProfile;
|
||||
import io.floci.cli.commands.config.ConfigValidateCommand;
|
||||
import picocli.CommandLine.Command;
|
||||
|
||||
@Command(
|
||||
name = "validate",
|
||||
description = "Validate a docker-compose.yml file for Floci OCI compatibility",
|
||||
mixinStandardHelpOptions = true
|
||||
)
|
||||
public class OciConfigValidateCommand implements Callable<Integer> {
|
||||
public class OciConfigValidateCommand extends ConfigValidateCommand {
|
||||
|
||||
@Mixin
|
||||
OciGlobalOptions 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 Kafka/Redpanda support");
|
||||
}
|
||||
|
||||
if (!Pattern.compile("4599\\s*:\\s*4599").matcher(content).find()) {
|
||||
issues.add("Port mapping 4599:4599 not found — Floci OCI listens on 4599 by default");
|
||||
}
|
||||
|
||||
if (!content.contains("floci/floci-oci") && !content.contains("ghcr.io/floci-io/floci-oci")) {
|
||||
warnings.add("Floci OCI image reference not detected — ensure your service uses floci/floci-oci");
|
||||
}
|
||||
|
||||
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;
|
||||
public OciConfigValidateCommand() {
|
||||
super(ProductProfile.OCI, false, "Functions (Fn Project sidecar)");
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import picocli.CommandLine.*;
|
||||
|
||||
@Command(
|
||||
name = "snapshot",
|
||||
description = "Manage Floci OCI state snapshots (coming soon)",
|
||||
description = "Manage Floci OCI state snapshots",
|
||||
mixinStandardHelpOptions = true,
|
||||
subcommands = {
|
||||
OciSnapshotSaveCommand.class,
|
||||
|
||||
@@ -1,28 +1,17 @@
|
||||
package io.floci.cli.commands.oci.snapshot;
|
||||
|
||||
import io.floci.cli.OciGlobalOptions;
|
||||
import io.floci.cli.output.Ansi;
|
||||
import picocli.CommandLine.*;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
import io.floci.cli.ProductProfile;
|
||||
import io.floci.cli.commands.snapshot.SnapshotDeleteCommand;
|
||||
import picocli.CommandLine.Command;
|
||||
|
||||
@Command(
|
||||
name = "delete",
|
||||
description = "Delete a Floci OCI snapshot",
|
||||
mixinStandardHelpOptions = true
|
||||
)
|
||||
public class OciSnapshotDeleteCommand implements Callable<Integer> {
|
||||
public class OciSnapshotDeleteCommand extends SnapshotDeleteCommand {
|
||||
|
||||
@Mixin
|
||||
OciGlobalOptions 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 OCI.") +
|
||||
"\nTrack progress: https://github.com/floci-io/floci-oci/issues");
|
||||
return 0;
|
||||
public OciSnapshotDeleteCommand() {
|
||||
super(ProductProfile.OCI);
|
||||
}
|
||||
}
|
||||
@@ -1,31 +1,17 @@
|
||||
package io.floci.cli.commands.oci.snapshot;
|
||||
|
||||
import io.floci.cli.OciGlobalOptions;
|
||||
import io.floci.cli.output.Ansi;
|
||||
import picocli.CommandLine.*;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
import io.floci.cli.ProductProfile;
|
||||
import io.floci.cli.commands.snapshot.SnapshotExportCommand;
|
||||
import picocli.CommandLine.Command;
|
||||
|
||||
@Command(
|
||||
name = "export",
|
||||
description = "Export a Floci OCI snapshot to a tarball file",
|
||||
mixinStandardHelpOptions = true
|
||||
)
|
||||
public class OciSnapshotExportCommand implements Callable<Integer> {
|
||||
public class OciSnapshotExportCommand extends SnapshotExportCommand {
|
||||
|
||||
@Mixin
|
||||
OciGlobalOptions 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 OCI.") +
|
||||
"\nTrack progress: https://github.com/floci-io/floci-oci/issues");
|
||||
return 0;
|
||||
public OciSnapshotExportCommand() {
|
||||
super(ProductProfile.OCI);
|
||||
}
|
||||
}
|
||||
@@ -1,31 +1,17 @@
|
||||
package io.floci.cli.commands.oci.snapshot;
|
||||
|
||||
import io.floci.cli.OciGlobalOptions;
|
||||
import io.floci.cli.output.Ansi;
|
||||
import picocli.CommandLine.*;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
import io.floci.cli.ProductProfile;
|
||||
import io.floci.cli.commands.snapshot.SnapshotImportCommand;
|
||||
import picocli.CommandLine.Command;
|
||||
|
||||
@Command(
|
||||
name = "import",
|
||||
description = "Import a Floci OCI snapshot from a tarball file",
|
||||
mixinStandardHelpOptions = true
|
||||
)
|
||||
public class OciSnapshotImportCommand implements Callable<Integer> {
|
||||
public class OciSnapshotImportCommand extends SnapshotImportCommand {
|
||||
|
||||
@Mixin
|
||||
OciGlobalOptions global;
|
||||
|
||||
@Parameters(index = "0", description = "Snapshot name", paramLabel = "<name>")
|
||||
String name;
|
||||
|
||||
@Option(names = {"--file", "-f"}, description = "Source file path", required = true, paramLabel = "<path>")
|
||||
String inputFile;
|
||||
|
||||
@Override
|
||||
public Integer call() {
|
||||
global.printer().println(Ansi.yellow("Snapshots are not yet available for Floci OCI.") +
|
||||
"\nTrack progress: https://github.com/floci-io/floci-oci/issues");
|
||||
return 0;
|
||||
public OciSnapshotImportCommand() {
|
||||
super(ProductProfile.OCI);
|
||||
}
|
||||
}
|
||||
@@ -1,34 +1,17 @@
|
||||
package io.floci.cli.commands.oci.snapshot;
|
||||
|
||||
import io.floci.cli.OciGlobalOptions;
|
||||
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;
|
||||
import io.floci.cli.ProductProfile;
|
||||
import io.floci.cli.commands.snapshot.SnapshotListCommand;
|
||||
import picocli.CommandLine.Command;
|
||||
|
||||
@Command(
|
||||
name = "list",
|
||||
description = "List available Floci OCI snapshots",
|
||||
mixinStandardHelpOptions = true
|
||||
)
|
||||
public class OciSnapshotListCommand implements Callable<Integer> {
|
||||
public class OciSnapshotListCommand extends SnapshotListCommand {
|
||||
|
||||
@Mixin
|
||||
OciGlobalOptions 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 OCI is coming — https://github.com/floci-io/floci-oci/issues)");
|
||||
return 0;
|
||||
public OciSnapshotListCommand() {
|
||||
super(ProductProfile.OCI);
|
||||
}
|
||||
}
|
||||
@@ -1,28 +1,17 @@
|
||||
package io.floci.cli.commands.oci.snapshot;
|
||||
|
||||
import io.floci.cli.OciGlobalOptions;
|
||||
import io.floci.cli.output.Ansi;
|
||||
import picocli.CommandLine.*;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
import io.floci.cli.ProductProfile;
|
||||
import io.floci.cli.commands.snapshot.SnapshotLoadCommand;
|
||||
import picocli.CommandLine.Command;
|
||||
|
||||
@Command(
|
||||
name = "load",
|
||||
description = "Load a Floci OCI snapshot",
|
||||
mixinStandardHelpOptions = true
|
||||
)
|
||||
public class OciSnapshotLoadCommand implements Callable<Integer> {
|
||||
public class OciSnapshotLoadCommand extends SnapshotLoadCommand {
|
||||
|
||||
@Mixin
|
||||
OciGlobalOptions 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 OCI.") +
|
||||
"\nTrack progress: https://github.com/floci-io/floci-oci/issues");
|
||||
return 0;
|
||||
public OciSnapshotLoadCommand() {
|
||||
super(ProductProfile.OCI);
|
||||
}
|
||||
}
|
||||
@@ -1,31 +1,17 @@
|
||||
package io.floci.cli.commands.oci.snapshot;
|
||||
|
||||
import io.floci.cli.OciGlobalOptions;
|
||||
import io.floci.cli.output.Ansi;
|
||||
import picocli.CommandLine.*;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
import io.floci.cli.ProductProfile;
|
||||
import io.floci.cli.commands.snapshot.SnapshotSaveCommand;
|
||||
import picocli.CommandLine.Command;
|
||||
|
||||
@Command(
|
||||
name = "save",
|
||||
description = "Save the current Floci OCI state as a named snapshot",
|
||||
mixinStandardHelpOptions = true
|
||||
)
|
||||
public class OciSnapshotSaveCommand implements Callable<Integer> {
|
||||
public class OciSnapshotSaveCommand extends SnapshotSaveCommand {
|
||||
|
||||
@Mixin
|
||||
OciGlobalOptions 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 OCI.") +
|
||||
"\nTrack progress: https://github.com/floci-io/floci-oci/issues");
|
||||
return 0;
|
||||
public OciSnapshotSaveCommand() {
|
||||
super(ProductProfile.OCI);
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import picocli.CommandLine.*;
|
||||
|
||||
@Command(
|
||||
name = "snapshot",
|
||||
description = "Manage Floci state snapshots",
|
||||
description = "Manage Floci AWS state snapshots",
|
||||
mixinStandardHelpOptions = true,
|
||||
subcommands = {
|
||||
SnapshotSaveCommand.class,
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package io.floci.cli.commands.snapshot;
|
||||
|
||||
import io.floci.cli.GlobalOptions;
|
||||
import io.floci.cli.ProductProfile;
|
||||
import io.floci.cli.docker.DockerClient;
|
||||
import io.floci.cli.http.FlociException;
|
||||
import io.floci.cli.http.FlociHttpClient;
|
||||
import io.floci.cli.output.Ansi;
|
||||
@@ -11,13 +13,24 @@ import java.util.concurrent.Callable;
|
||||
|
||||
@Command(
|
||||
name = "delete",
|
||||
description = "Delete a snapshot",
|
||||
description = "Delete a Floci AWS snapshot",
|
||||
mixinStandardHelpOptions = true
|
||||
)
|
||||
public class SnapshotDeleteCommand implements Callable<Integer> {
|
||||
|
||||
protected final ProductProfile profile;
|
||||
|
||||
@Mixin
|
||||
GlobalOptions global;
|
||||
protected GlobalOptions global;
|
||||
|
||||
public SnapshotDeleteCommand() {
|
||||
this(ProductProfile.AWS);
|
||||
}
|
||||
|
||||
protected SnapshotDeleteCommand(ProductProfile profile) {
|
||||
this.profile = profile;
|
||||
this.global = new GlobalOptions(profile);
|
||||
}
|
||||
|
||||
@Parameters(index = "0", description = "Snapshot name", paramLabel = "<name>")
|
||||
String name;
|
||||
@@ -25,7 +38,10 @@ public class SnapshotDeleteCommand implements Callable<Integer> {
|
||||
@Override
|
||||
public Integer call() {
|
||||
Printer printer = global.printer();
|
||||
FlociHttpClient client = new FlociHttpClient(global.endpoint);
|
||||
// Resolve the endpoint from the container's port mapping, like status/services/wait do,
|
||||
// so a container started with --port <n> is still found without --endpoint.
|
||||
String effectiveEndpoint = global.resolvedEndpoint(new DockerClient());
|
||||
FlociHttpClient client = new FlociHttpClient(effectiveEndpoint, profile.controlPrefix());
|
||||
try {
|
||||
client.deleteSnapshot(name);
|
||||
printer.println(Ansi.green("Snapshot deleted:") + " " + name);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package io.floci.cli.commands.snapshot;
|
||||
|
||||
import io.floci.cli.GlobalOptions;
|
||||
import io.floci.cli.ProductProfile;
|
||||
import io.floci.cli.output.Printer;
|
||||
import picocli.CommandLine.*;
|
||||
|
||||
@@ -8,13 +9,24 @@ import java.util.concurrent.Callable;
|
||||
|
||||
@Command(
|
||||
name = "export",
|
||||
description = "Export a snapshot to a tarball file",
|
||||
description = "Export a Floci AWS snapshot to a tarball file",
|
||||
mixinStandardHelpOptions = true
|
||||
)
|
||||
public class SnapshotExportCommand implements Callable<Integer> {
|
||||
|
||||
protected final ProductProfile profile;
|
||||
|
||||
@Mixin
|
||||
GlobalOptions global;
|
||||
protected GlobalOptions global;
|
||||
|
||||
public SnapshotExportCommand() {
|
||||
this(ProductProfile.AWS);
|
||||
}
|
||||
|
||||
protected SnapshotExportCommand(ProductProfile profile) {
|
||||
this.profile = profile;
|
||||
this.global = new GlobalOptions(profile);
|
||||
}
|
||||
|
||||
@Parameters(index = "0", description = "Snapshot name", paramLabel = "<name>")
|
||||
String name;
|
||||
@@ -27,7 +39,7 @@ public class SnapshotExportCommand implements Callable<Integer> {
|
||||
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.");
|
||||
"Track progress: " + profile.serverRepo() + "/issues");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package io.floci.cli.commands.snapshot;
|
||||
|
||||
import io.floci.cli.GlobalOptions;
|
||||
import io.floci.cli.ProductProfile;
|
||||
import io.floci.cli.output.Printer;
|
||||
import picocli.CommandLine.*;
|
||||
|
||||
@@ -8,13 +9,24 @@ import java.util.concurrent.Callable;
|
||||
|
||||
@Command(
|
||||
name = "import",
|
||||
description = "Import a snapshot from a tarball file",
|
||||
description = "Import a Floci AWS snapshot from a tarball file",
|
||||
mixinStandardHelpOptions = true
|
||||
)
|
||||
public class SnapshotImportCommand implements Callable<Integer> {
|
||||
|
||||
protected final ProductProfile profile;
|
||||
|
||||
@Mixin
|
||||
GlobalOptions global;
|
||||
protected GlobalOptions global;
|
||||
|
||||
public SnapshotImportCommand() {
|
||||
this(ProductProfile.AWS);
|
||||
}
|
||||
|
||||
protected SnapshotImportCommand(ProductProfile profile) {
|
||||
this.profile = profile;
|
||||
this.global = new GlobalOptions(profile);
|
||||
}
|
||||
|
||||
@Option(names = {"--file", "-f"}, description = "Source tarball path", required = true, paramLabel = "<path>")
|
||||
String inputFile;
|
||||
@@ -27,7 +39,7 @@ public class SnapshotImportCommand implements Callable<Integer> {
|
||||
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.");
|
||||
"Track progress: " + profile.serverRepo() + "/issues");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
package io.floci.cli.commands.snapshot;
|
||||
|
||||
import io.floci.cli.GlobalOptions;
|
||||
import io.floci.cli.ProductProfile;
|
||||
import io.floci.cli.docker.DockerClient;
|
||||
import io.floci.cli.http.FlociException;
|
||||
import io.floci.cli.http.FlociHttpClient;
|
||||
import io.floci.cli.output.Ansi;
|
||||
@@ -12,18 +14,32 @@ import java.util.concurrent.Callable;
|
||||
|
||||
@Command(
|
||||
name = "list",
|
||||
description = "List available snapshots",
|
||||
description = "List available Floci AWS snapshots",
|
||||
mixinStandardHelpOptions = true
|
||||
)
|
||||
public class SnapshotListCommand implements Callable<Integer> {
|
||||
|
||||
protected final ProductProfile profile;
|
||||
|
||||
@Mixin
|
||||
GlobalOptions global;
|
||||
protected GlobalOptions global;
|
||||
|
||||
public SnapshotListCommand() {
|
||||
this(ProductProfile.AWS);
|
||||
}
|
||||
|
||||
protected SnapshotListCommand(ProductProfile profile) {
|
||||
this.profile = profile;
|
||||
this.global = new GlobalOptions(profile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer call() {
|
||||
Printer printer = global.printer();
|
||||
FlociHttpClient client = new FlociHttpClient(global.endpoint);
|
||||
// Resolve the endpoint from the container's port mapping, like status/services/wait do,
|
||||
// so a container started with --port <n> is still found without --endpoint.
|
||||
String effectiveEndpoint = global.resolvedEndpoint(new DockerClient());
|
||||
FlociHttpClient client = new FlociHttpClient(effectiveEndpoint, profile.controlPrefix());
|
||||
try {
|
||||
var node = client.listSnapshots();
|
||||
if (printer.format() != OutputFormat.text) {
|
||||
@@ -40,7 +56,7 @@ public class SnapshotListCommand implements Callable<Integer> {
|
||||
} 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.");
|
||||
"Track progress: " + profile.serverRepo() + "/issues");
|
||||
} else {
|
||||
printer.error("Failed to list snapshots: " + e.getMessage());
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package io.floci.cli.commands.snapshot;
|
||||
|
||||
import io.floci.cli.GlobalOptions;
|
||||
import io.floci.cli.ProductProfile;
|
||||
import io.floci.cli.docker.DockerClient;
|
||||
import io.floci.cli.http.FlociException;
|
||||
import io.floci.cli.http.FlociHttpClient;
|
||||
import io.floci.cli.output.Ansi;
|
||||
@@ -11,13 +13,24 @@ import java.util.concurrent.Callable;
|
||||
|
||||
@Command(
|
||||
name = "load",
|
||||
description = "Restore a saved snapshot",
|
||||
description = "Load a Floci AWS snapshot",
|
||||
mixinStandardHelpOptions = true
|
||||
)
|
||||
public class SnapshotLoadCommand implements Callable<Integer> {
|
||||
|
||||
protected final ProductProfile profile;
|
||||
|
||||
@Mixin
|
||||
GlobalOptions global;
|
||||
protected GlobalOptions global;
|
||||
|
||||
public SnapshotLoadCommand() {
|
||||
this(ProductProfile.AWS);
|
||||
}
|
||||
|
||||
protected SnapshotLoadCommand(ProductProfile profile) {
|
||||
this.profile = profile;
|
||||
this.global = new GlobalOptions(profile);
|
||||
}
|
||||
|
||||
@Parameters(index = "0", description = "Snapshot name", paramLabel = "<name>")
|
||||
String name;
|
||||
@@ -25,7 +38,10 @@ public class SnapshotLoadCommand implements Callable<Integer> {
|
||||
@Override
|
||||
public Integer call() {
|
||||
Printer printer = global.printer();
|
||||
FlociHttpClient client = new FlociHttpClient(global.endpoint);
|
||||
// Resolve the endpoint from the container's port mapping, like status/services/wait do,
|
||||
// so a container started with --port <n> is still found without --endpoint.
|
||||
String effectiveEndpoint = global.resolvedEndpoint(new DockerClient());
|
||||
FlociHttpClient client = new FlociHttpClient(effectiveEndpoint, profile.controlPrefix());
|
||||
try {
|
||||
client.loadSnapshot(name);
|
||||
printer.println(Ansi.green("Snapshot loaded:") + " " + name);
|
||||
@@ -33,7 +49,7 @@ public class SnapshotLoadCommand implements Callable<Integer> {
|
||||
} 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.");
|
||||
"Track progress: " + profile.serverRepo() + "/issues");
|
||||
} else {
|
||||
printer.error("Failed to load snapshot: " + e.getMessage());
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package io.floci.cli.commands.snapshot;
|
||||
|
||||
import io.floci.cli.GlobalOptions;
|
||||
import io.floci.cli.ProductProfile;
|
||||
import io.floci.cli.docker.DockerClient;
|
||||
import io.floci.cli.http.FlociException;
|
||||
import io.floci.cli.http.FlociHttpClient;
|
||||
import io.floci.cli.output.Ansi;
|
||||
@@ -11,13 +13,24 @@ import java.util.concurrent.Callable;
|
||||
|
||||
@Command(
|
||||
name = "save",
|
||||
description = "Save the current Floci state as a named snapshot",
|
||||
description = "Save the current Floci AWS state as a named snapshot",
|
||||
mixinStandardHelpOptions = true
|
||||
)
|
||||
public class SnapshotSaveCommand implements Callable<Integer> {
|
||||
|
||||
protected final ProductProfile profile;
|
||||
|
||||
@Mixin
|
||||
GlobalOptions global;
|
||||
protected GlobalOptions global;
|
||||
|
||||
public SnapshotSaveCommand() {
|
||||
this(ProductProfile.AWS);
|
||||
}
|
||||
|
||||
protected SnapshotSaveCommand(ProductProfile profile) {
|
||||
this.profile = profile;
|
||||
this.global = new GlobalOptions(profile);
|
||||
}
|
||||
|
||||
@Parameters(index = "0", description = "Snapshot name", paramLabel = "<name>")
|
||||
String name;
|
||||
@@ -28,7 +41,10 @@ public class SnapshotSaveCommand implements Callable<Integer> {
|
||||
@Override
|
||||
public Integer call() {
|
||||
Printer printer = global.printer();
|
||||
FlociHttpClient client = new FlociHttpClient(global.endpoint);
|
||||
// Resolve the endpoint from the container's port mapping, like status/services/wait do,
|
||||
// so a container started with --port <n> is still found without --endpoint.
|
||||
String effectiveEndpoint = global.resolvedEndpoint(new DockerClient());
|
||||
FlociHttpClient client = new FlociHttpClient(effectiveEndpoint, profile.controlPrefix());
|
||||
try {
|
||||
client.postSnapshot(name);
|
||||
printer.println(Ansi.green("Snapshot saved:") + " " + name);
|
||||
@@ -36,7 +52,7 @@ public class SnapshotSaveCommand implements Callable<Integer> {
|
||||
} 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.");
|
||||
"Track progress: " + profile.serverRepo() + "/issues");
|
||||
} else {
|
||||
printer.error("Failed to save snapshot: " + e.getMessage());
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package io.floci.cli.util;
|
||||
|
||||
/** Parses human-friendly duration strings like {@code 30s}, {@code 2m}, {@code 500ms}. */
|
||||
public final class Durations {
|
||||
|
||||
/** Returns milliseconds; a bare number is seconds; null/blank defaults to 30s. */
|
||||
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;
|
||||
}
|
||||
|
||||
private Durations() {}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package io.floci.cli.unit;
|
||||
|
||||
import io.floci.cli.ProductProfile;
|
||||
import io.floci.cli.commands.DoctorCommand;
|
||||
import io.floci.cli.doctor.Check;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/** Pins the per-product doctor check composition and order (Docker checks first, then companions). */
|
||||
class DoctorCheckListTest {
|
||||
|
||||
private static final List<String> BASE = List.of(
|
||||
"DockerInstalledCheck", "DockerDaemonCheck", "DockerSocketCheck", "DockerVersionCheck",
|
||||
"PortAvailableCheck", "ImagePresentCheck", "ImageVersionCheck",
|
||||
"ContainerRunningCheck", "EndpointReachableCheck");
|
||||
|
||||
private static List<String> names(List<Check> checks) {
|
||||
return checks.stream().map(c -> c.getClass().getSimpleName()).toList();
|
||||
}
|
||||
|
||||
@Test
|
||||
void awsHasBaseChecksPlusAwsCliCompanions() {
|
||||
var names = names(new DoctorCommand().allChecks());
|
||||
assertEquals(BASE.size() + 2, names.size());
|
||||
assertEquals(BASE, names.subList(0, BASE.size()));
|
||||
assertEquals(List.of("AwsCliEndpointCheck", "AwsCliS3PathStyleCheck"), names.subList(BASE.size(), names.size()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void azHasBaseChecksPlusAzCliCompanions() {
|
||||
var names = names(new DoctorCommand(ProductProfile.AZ, DoctorCommand.AZ_COMPANION_CHECKS).allChecks());
|
||||
assertEquals(BASE, names.subList(0, BASE.size()));
|
||||
assertEquals(List.of("AzCliInstalledCheck", "AzCliConnectionStringCheck"), names.subList(BASE.size(), names.size()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void gcpAndOciHaveExactlyTheBaseChecks() {
|
||||
for (ProductProfile p : List.of(ProductProfile.GCP, ProductProfile.OCI)) {
|
||||
assertEquals(BASE, names(new DoctorCommand(p, List.of()).allChecks()), p.name());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
package io.floci.cli.unit;
|
||||
|
||||
import io.floci.cli.GlobalOptions;
|
||||
import io.floci.cli.ProductProfile;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.function.UnaryOperator;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class GlobalOptionsTest {
|
||||
|
||||
private static UnaryOperator<String> env(Map<String, String> vars) {
|
||||
return vars::get;
|
||||
}
|
||||
|
||||
@Test
|
||||
void productDefaultsWhenEnvUnset() {
|
||||
GlobalOptions gcp = new GlobalOptions(ProductProfile.GCP, env(Map.of()));
|
||||
assertEquals("http://localhost:4588", gcp.endpoint);
|
||||
assertEquals("floci-gcp", gcp.container);
|
||||
|
||||
GlobalOptions oci = new GlobalOptions(ProductProfile.OCI, env(Map.of()));
|
||||
assertEquals("http://localhost:4599", oci.endpoint);
|
||||
assertEquals("floci-oci", oci.container);
|
||||
}
|
||||
|
||||
@Test
|
||||
void envVarOverridesDefault() {
|
||||
GlobalOptions az = new GlobalOptions(ProductProfile.AZ,
|
||||
env(Map.of("FLOCI_AZ_ENDPOINT", "http://remote:9999", "FLOCI_AZ_CONTAINER", "custom")));
|
||||
assertEquals("http://remote:9999", az.endpoint);
|
||||
assertEquals("custom", az.container);
|
||||
}
|
||||
|
||||
@Test
|
||||
void wrongProductEnvVarIsIgnored() {
|
||||
GlobalOptions gcp = new GlobalOptions(ProductProfile.GCP,
|
||||
env(Map.of("FLOCI_ENDPOINT", "http://aws-only:1")));
|
||||
assertEquals("http://localhost:4588", gcp.endpoint);
|
||||
}
|
||||
|
||||
@Test
|
||||
void emptyEnvVarCountsAsSet() {
|
||||
// Matches picocli ${VAR:-fallback} semantics: only null falls back.
|
||||
GlobalOptions aws = new GlobalOptions(ProductProfile.AWS,
|
||||
env(Map.of("FLOCI_ENDPOINT", "")));
|
||||
assertEquals("", aws.endpoint);
|
||||
}
|
||||
|
||||
@Test
|
||||
void noArgConstructorIsAws() {
|
||||
GlobalOptions options = new GlobalOptions();
|
||||
assertEquals(ProductProfile.AWS, options.product);
|
||||
// Cannot assert endpoint literal here: real env may set FLOCI_ENDPOINT.
|
||||
}
|
||||
|
||||
@Test
|
||||
void endpointFromPortsUsesProductFallbackPortForPortlessEndpoint() {
|
||||
// Endpoint URL without a port → the product's default port must be matched.
|
||||
for (ProductProfile p : new ProductProfile[]{
|
||||
ProductProfile.AWS, ProductProfile.GCP, ProductProfile.AZ, ProductProfile.OCI}) {
|
||||
GlobalOptions options = new GlobalOptions(p, env(Map.of()));
|
||||
String result = options.endpointFromPorts(
|
||||
"12345->" + p.defaultPort() + "/tcp", "http://localhost");
|
||||
assertEquals("http://localhost:12345", result, p.name());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void endpointFromPortsMatchesExplicitPort() {
|
||||
GlobalOptions gcp = new GlobalOptions(ProductProfile.GCP, env(Map.of()));
|
||||
assertEquals("http://localhost:9999",
|
||||
gcp.endpointFromPorts("9999->4588/tcp", "http://localhost:4588"));
|
||||
assertEquals("http://localhost:4588",
|
||||
gcp.endpointFromPorts("9999->1111/tcp", "http://localhost:4588"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package io.floci.cli.unit;
|
||||
|
||||
import io.floci.cli.ProductProfile;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/** Pins every field of the four product constants — the drift firewall for the unified tree. */
|
||||
class ProductProfileTest {
|
||||
|
||||
@Test
|
||||
void aws() {
|
||||
assertEquals("aws", ProductProfile.AWS.name());
|
||||
assertEquals("Floci AWS", ProductProfile.AWS.displayName());
|
||||
assertEquals("floci/floci", ProductProfile.AWS.image());
|
||||
assertEquals("floci/floci:latest", ProductProfile.AWS.defaultImageRef());
|
||||
assertEquals("floci", ProductProfile.AWS.defaultContainer());
|
||||
assertEquals(4566, ProductProfile.AWS.defaultPort());
|
||||
assertEquals("http://localhost:4566", ProductProfile.AWS.defaultEndpoint());
|
||||
assertEquals("FLOCI_ENDPOINT", ProductProfile.AWS.envVar("ENDPOINT"));
|
||||
assertEquals("/_floci", ProductProfile.AWS.controlPrefix());
|
||||
assertEquals("floci", ProductProfile.AWS.commandPrefix());
|
||||
}
|
||||
|
||||
@Test
|
||||
void gcp() {
|
||||
assertEquals("gcp", ProductProfile.GCP.name());
|
||||
assertEquals("Floci GCP", ProductProfile.GCP.displayName());
|
||||
assertEquals("floci/floci-gcp", ProductProfile.GCP.image());
|
||||
assertEquals("floci-gcp", ProductProfile.GCP.defaultContainer());
|
||||
assertEquals(4588, ProductProfile.GCP.defaultPort());
|
||||
assertEquals("FLOCI_GCP_CONTAINER", ProductProfile.GCP.envVar("CONTAINER"));
|
||||
assertEquals("/_floci-gcp", ProductProfile.GCP.controlPrefix());
|
||||
assertEquals("floci gcp", ProductProfile.GCP.commandPrefix());
|
||||
}
|
||||
|
||||
@Test
|
||||
void az() {
|
||||
assertEquals("az", ProductProfile.AZ.name());
|
||||
assertEquals("Floci Azure", ProductProfile.AZ.displayName());
|
||||
assertEquals("floci/floci-az", ProductProfile.AZ.image());
|
||||
assertEquals("floci-az", ProductProfile.AZ.defaultContainer());
|
||||
assertEquals(4577, ProductProfile.AZ.defaultPort());
|
||||
assertEquals("FLOCI_AZ_ENDPOINT", ProductProfile.AZ.envVar("ENDPOINT"));
|
||||
// The floci-az server exposes /_floci/* (same as AWS), NOT /_floci-az.
|
||||
assertEquals("/_floci", ProductProfile.AZ.controlPrefix());
|
||||
assertEquals("floci az", ProductProfile.AZ.commandPrefix());
|
||||
}
|
||||
|
||||
@Test
|
||||
void oci() {
|
||||
assertEquals("oci", ProductProfile.OCI.name());
|
||||
assertEquals("Floci OCI", ProductProfile.OCI.displayName());
|
||||
assertEquals("floci/floci-oci", ProductProfile.OCI.image());
|
||||
assertEquals("floci-oci", ProductProfile.OCI.defaultContainer());
|
||||
assertEquals(4599, ProductProfile.OCI.defaultPort());
|
||||
assertEquals("FLOCI_OCI_ENDPOINT", ProductProfile.OCI.envVar("ENDPOINT"));
|
||||
assertEquals("/_floci-oci", ProductProfile.OCI.controlPrefix());
|
||||
assertEquals("floci oci", ProductProfile.OCI.commandPrefix());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
package io.floci.cli.unit;
|
||||
|
||||
import io.floci.cli.FlociCli;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import picocli.CommandLine;
|
||||
import picocli.CommandLine.Model.CommandSpec;
|
||||
import picocli.CommandLine.ParseResult;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* Characterization tests pinning the CLI surface of all four product trees.
|
||||
* Written against the copied-tree implementation; they must keep passing
|
||||
* unchanged through the ProductProfile unification refactor.
|
||||
*/
|
||||
class ProductTreesParsingTest {
|
||||
|
||||
private static final Set<String> LIFECYCLE_COMMANDS = Set.of(
|
||||
"start", "stop", "restart", "status", "logs", "wait",
|
||||
"version", "services", "doctor", "env", "config", "snapshot", "completion", "help");
|
||||
|
||||
private static CommandSpec leafSpec(String... args) {
|
||||
ParseResult r = new CommandLine(new FlociCli()).parseArgs(args);
|
||||
while (r.hasSubcommand()) r = r.subcommand();
|
||||
return r.commandSpec();
|
||||
}
|
||||
|
||||
private static void assertDefaults(String expectedEndpoint, String expectedContainer, String... args) {
|
||||
CommandSpec spec = leafSpec(args);
|
||||
assertEquals(expectedEndpoint, spec.findOption("--endpoint").getValue());
|
||||
assertEquals(expectedContainer, spec.findOption("--container").getValue());
|
||||
}
|
||||
|
||||
private static void assertStartDefaults(String port, String image, String... args) {
|
||||
CommandSpec spec = leafSpec(args);
|
||||
assertEquals(Integer.valueOf(port), spec.findOption("--port").getValue());
|
||||
assertEquals(image, spec.findOption("--image").getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
void awsTreeDefaults() {
|
||||
assertDefaults("http://localhost:4566", "floci", "status");
|
||||
assertDefaults("http://localhost:4566", "floci", "aws", "status");
|
||||
assertStartDefaults("4566", "floci/floci:latest", "start");
|
||||
assertStartDefaults("4566", "floci/floci:latest", "aws", "start");
|
||||
}
|
||||
|
||||
@Test
|
||||
void gcpTreeDefaults() {
|
||||
assertDefaults("http://localhost:4588", "floci-gcp", "gcp", "status");
|
||||
assertStartDefaults("4588", "floci/floci-gcp:latest", "gcp", "start");
|
||||
}
|
||||
|
||||
@Test
|
||||
void azTreeDefaults() {
|
||||
assertDefaults("http://localhost:4577", "floci-az", "az", "status");
|
||||
assertStartDefaults("4577", "floci/floci-az:latest", "az", "start");
|
||||
}
|
||||
|
||||
@Test
|
||||
void ociTreeDefaults() {
|
||||
assertDefaults("http://localhost:4599", "floci-oci", "oci", "status");
|
||||
assertStartDefaults("4599", "floci/floci-oci:latest", "oci", "start");
|
||||
}
|
||||
|
||||
@Test
|
||||
void endpointFlagOverridesDefaultInEveryTree() {
|
||||
for (String tree : new String[]{"aws", "gcp", "az", "oci"}) {
|
||||
CommandSpec spec = leafSpec(tree, "status", "--endpoint", "http://x:1");
|
||||
assertEquals("http://x:1", spec.findOption("--endpoint").getValue(), tree);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void everyProductGroupExposesTheFullCommandSet() {
|
||||
CommandLine root = new CommandLine(new FlociCli());
|
||||
for (String tree : new String[]{"aws", "gcp", "az", "oci"}) {
|
||||
Set<String> names = root.getSubcommands().get(tree).getSubcommands().keySet();
|
||||
assertTrue(names.containsAll(LIFECYCLE_COMMANDS),
|
||||
tree + " is missing " + LIFECYCLE_COMMANDS.stream().filter(c -> !names.contains(c)).toList());
|
||||
}
|
||||
// oci additionally has setup; bare root additionally has update + the product groups
|
||||
assertTrue(root.getSubcommands().get("oci").getSubcommands().containsKey("setup"));
|
||||
assertTrue(root.getSubcommands().keySet().containsAll(Set.of("update", "aws", "gcp", "az", "oci")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void productConfigGroupsHaveNoDefaultProduct() {
|
||||
CommandLine root = new CommandLine(new FlociCli());
|
||||
assertTrue(root.getSubcommands().get("config").getSubcommands().containsKey("default-product"));
|
||||
for (String tree : new String[]{"gcp", "az", "oci"}) {
|
||||
Set<String> configSubs = root.getSubcommands().get(tree)
|
||||
.getSubcommands().get("config").getSubcommands().keySet();
|
||||
assertTrue(configSubs.containsAll(Set.of("show", "validate", "profile")), tree);
|
||||
assertFalse(configSubs.contains("default-product"), tree);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void snapshotGroupsExposeAllLeaves() {
|
||||
CommandLine root = new CommandLine(new FlociCli());
|
||||
Set<String> expected = Set.of("save", "load", "list", "delete", "export", "import");
|
||||
assertTrue(root.getSubcommands().get("snapshot").getSubcommands().keySet().containsAll(expected));
|
||||
for (String tree : new String[]{"gcp", "az", "oci"}) {
|
||||
assertTrue(root.getSubcommands().get(tree)
|
||||
.getSubcommands().get("snapshot").getSubcommands().keySet().containsAll(expected), tree);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void sharedFlagsParseInEveryTree() {
|
||||
for (String tree : new String[]{"aws", "gcp", "az", "oci"}) {
|
||||
CommandSpec spec = leafSpec(tree, "status", "-o", "json", "-q", "--no-color", "-v");
|
||||
assertEquals("json", spec.findOption("--output").getValue().toString());
|
||||
assertEquals(Boolean.TRUE, spec.findOption("--quiet").getValue());
|
||||
assertEquals(Boolean.TRUE, spec.findOption("--no-color").getValue());
|
||||
assertEquals(Boolean.TRUE, spec.findOption("--verbose").getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package io.floci.cli.unit;
|
||||
|
||||
import io.floci.cli.commands.WaitCommand;
|
||||
import io.floci.cli.util.Durations;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.CsvSource;
|
||||
@@ -18,11 +18,11 @@ class WaitCommandParseTest {
|
||||
"10, 10000"
|
||||
})
|
||||
void testDurationParsing(String input, long expectedMillis) {
|
||||
assertEquals(expectedMillis, WaitCommand.parseDuration(input.trim()));
|
||||
assertEquals(expectedMillis, Durations.parseDuration(input.trim()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testNullDuration() {
|
||||
assertEquals(30_000, WaitCommand.parseDuration(null));
|
||||
assertEquals(30_000, Durations.parseDuration(null));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user