feat(cli): structured output for start, stop and restart, and a status exit code scripts can use (#60)

* feat(cli): structured output for start, stop and restart, and a status exit code scripts can use

start, stop and restart print one document with -o json or -o yaml and keep progress off stdout. status exits 1 when the instance is not up (it always exited 0). logs stays plain text and says so when -o is passed.

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

* feat(cli): report the container's real state after start and stop

start reads the state back, so a container that exited during the readiness wait is not reported as running, and stop reports a container docker removed on its own (--rm) as removed. The tests now reject anything after the one document on stdout.

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-11 08:59:58 -05:00
1 parent 804e355936
commit 4a9a9b5a4a
10 files changed
+588 -31

No files matched your search

@@ -70,6 +70,12 @@ public class WaitCommand implements Callable<Integer> {
*/
String knownEndpoint;
/**
* Set by {@code start}, which reports the outcome in its own structured result: this wait
* then prints no document of its own, so stdout carries exactly one.
*/
boolean embedded;
static final long FIRST_DELAY_MS = 25;
static final long MAX_DELAY_MS = 500;
static final Duration MAX_REQUEST_TIMEOUT = Duration.ofSeconds(10);
@@ -99,7 +105,7 @@ public class WaitCommand implements Callable<Integer> {
if (isReady(client, service, requestTimeout(Duration.between(Instant.now(), deadline)))) {
if (spinner) clearSpinner(printer);
if (printer.format() != OutputFormat.text) {
printer.structured(Map.of("ready", true, "endpoint", effectiveEndpoint));
if (!embedded) printer.structured(Map.of("ready", true, "endpoint", effectiveEndpoint));
} else {
printer.println(Ansi.green(profile.displayName() + " is ready") + " (" + effectiveEndpoint + ")");
}