mirror of
https://github.com/floci-io/floci-cli.git
synced 2026-11-22 21:50:47 -05:00
fix(cli): keep wait's spinner out of -o json, reject bad durations and make --verbose work (#48)
* fix(cli): keep wait's spinner out of -o json, reject bad durations and make --verbose work wait draws its spinner only for text output on a terminal and clears it before the result; --timeout values that are not a positive number with ms, s, m or h exit 2 with a hint instead of a stack trace; --verbose now echoes each docker command to stderr and prints stack traces for errors. * fix(cli): reject durations that overflow and pin the spinner rule on a terminal A duration is checked for sign before it is converted and the conversion is overflow-checked, so -9223372036854775807s no longer wraps to a positive timeout. wait takes its terminal check through a seam, with tests for json, yaml and text output on a terminal.
This commit is contained in:
1 parent
7ecc895baa
commit
52ebdee98d
8 files changed
+230
-10
No files matched your search
@@ -1,5 +1,6 @@
|
||||
package io.floci.cli.unit;
|
||||
|
||||
import io.floci.cli.GlobalOptions;
|
||||
import io.floci.cli.docker.DockerClient;
|
||||
import io.floci.cli.docker.DockerException;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -9,6 +10,8 @@ import org.junit.jupiter.api.io.TempDir;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.PrintStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.time.Duration;
|
||||
@@ -203,4 +206,26 @@ class DockerClientProcessTest {
|
||||
|
||||
assertEquals(List.of("rm", "--", "--rm-everything"), args);
|
||||
}
|
||||
|
||||
/** BL-041: with --verbose set, each docker command is echoed to stderr before it runs. */
|
||||
@Test
|
||||
@DisabledOnOs(OS.WINDOWS)
|
||||
void verboseEchoesTheDockerCommand() throws Exception {
|
||||
Path fakeDocker = tempDir.resolve("docker");
|
||||
Files.writeString(fakeDocker, "#!/bin/sh\nexit 0\n");
|
||||
assertTrue(fakeDocker.toFile().setExecutable(true));
|
||||
PrintStream err = System.err;
|
||||
ByteArrayOutputStream errBuf = new ByteArrayOutputStream();
|
||||
System.setErr(new PrintStream(errBuf));
|
||||
System.setProperty(GlobalOptions.VERBOSE_PROPERTY, "true");
|
||||
try {
|
||||
new DockerClient(fakeDocker.toString()).removeContainer("floci-x");
|
||||
} finally {
|
||||
System.clearProperty(GlobalOptions.VERBOSE_PROPERTY);
|
||||
System.setErr(err);
|
||||
}
|
||||
|
||||
assertTrue(errBuf.toString().contains("+ docker rm"), errBuf.toString());
|
||||
assertTrue(errBuf.toString().contains("floci-x"), errBuf.toString());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user