feat(reset): add floci reset to delete every resource in a running emulator (#55)

* feat(reset): add floci reset to delete every resource in a running emulator

floci reset (and floci gcp/az/oci reset) calls the emulator's state reset endpoint, so a test run can start clean without restarting the container. It asks for confirmation on a terminal; --yes skips the prompt and is required when there is no terminal. A server without the endpoint (floci-az today) gets a 'not available' message.

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

* feat(reset): never guess which server to reset

A typed --endpoint is used as given instead of being replaced by a local container's port, and a container the user selected has to be found running: a missing or stopped one resets nothing rather than falling back to the default instance. The confirmation goes through a seam, with tests for every answer.

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

* feat(reset): stop when a selected container publishes no port for the emulator

A selected container that is running without a matching published port has nothing to be found by, and the configured endpoint may be another instance.

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

* feat(reset): find a selected instance by the emulator's port, not the configured host port

A profile for an instance on its own host port names that port in its endpoint, while the container still listens on the emulator's; reset matched the wrong one and refused such instances.

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

---------

Signed-off-by: Hector Ventura <hectorvent@gmail.com>
This commit is contained in:
Hector Ventura authored and GitHub committed 2026-10-10 22:07:41 -05:00
1 parent 24b4280f69
commit fa306b38a6
15 files changed
+667 -13

No files matched your search

+24 -11
View File
@@ -9,6 +9,7 @@ import picocli.CommandLine.Option;
import picocli.CommandLine.Spec;
import java.net.URI;
import java.util.Optional;
import java.util.function.UnaryOperator;
import java.util.regex.Pattern;
@@ -105,7 +106,8 @@ public class GlobalOptions {
return "";
}
private boolean typed(String option) {
/** Whether {@code option} was given on the command line, as opposed to coming from a profile, the environment or the default. */
public boolean typed(String option) {
try {
return mixee != null && mixee.commandLine() != null
&& mixee.commandLine().getParseResult() != null
@@ -150,20 +152,31 @@ public class GlobalOptions {
try {
int containerPort = URI.create(fallback).getPort();
if (containerPort == -1) containerPort = product.defaultPort();
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;
}
}
return publishedEndpoint(ports, containerPort).orElse(fallback);
} catch (Exception ignored) {}
return fallback;
}
/**
* Where a container with these published {@code ports} ("14566->4566/tcp ...") is reached for
* its {@code containerPort}, or empty when that port is not published. For callers that must
* not fall back to a configured endpoint.
*/
public static Optional<String> publishedEndpoint(String ports, int containerPort) {
if (ports == null || ports.isBlank()) return Optional.empty();
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 Optional.of("http://localhost:" + hostPort);
}
}
return Optional.empty();
}
private static boolean isStdoutTty() {
return System.console() != null;
}