fix(cli): honour --no-color on parse errors and show profile defaults in --help (#35)

This commit is contained in:
Hector Ventura authored and GitHub committed 2026-10-08 22:30:28 -05:00
1 parent bc59dff8c3
commit fc67e72a62
8 files changed
+126 -13

No files matched your search

+13 -1
View File
@@ -16,6 +16,8 @@ import io.floci.cli.update.UpdateNotifier;
import picocli.CommandLine;
import picocli.CommandLine.*;
import java.util.Arrays;
@Command(
name = "floci",
description = "Manage your local Floci emulators%n%n" +
@@ -74,7 +76,7 @@ public class FlociCli implements Runnable {
}
public static void main(String[] args) {
if (System.getenv("NO_COLOR") != null || System.console() == null) {
if (colorDisabled(args, System.getenv("NO_COLOR") != null, System.console() != null)) {
Ansi.disable();
}
@@ -146,6 +148,16 @@ public class FlociCli implements Runnable {
};
}
/**
* Whether this invocation prints without ANSI colour. {@code --no-color} is read from the raw
* arguments here as well as by {@code GlobalOptions.printer()}: a parse error is printed by the
* exception handlers before any command, and so any printer, exists.
*/
public static boolean colorDisabled(String[] args, boolean noColorEnv, boolean interactive) {
return noColorEnv || !interactive || Arrays.stream(args)
.anyMatch(a -> a.equals("--no-color") || a.equalsIgnoreCase("--no-color=true"));
}
// Returns true when routing should NOT apply: explicit product subgroup,
// or a product-independent command like "config" or "completion".
private static boolean isExplicitProduct(String[] args) {