From cd41ee917e67ad1507e865a0dbd1179d63dfed05 Mon Sep 17 00:00:00 2001 From: mikera Date: Tue, 30 Jul 2024 12:38:50 +0100 Subject: [PATCH] More CLI output improvements, add --no-color option --- convex-cli/src/main/java/convex/cli/Main.java | 17 ++++++++++++----- .../src/main/java/convex/cli/client/Query.java | 2 +- convex-core/src/main/java/etch/Etch.java | 2 +- .../src/main/java/convex/net/Connection.java | 10 +++++----- 4 files changed, 19 insertions(+), 12 deletions(-) diff --git a/convex-cli/src/main/java/convex/cli/Main.java b/convex-cli/src/main/java/convex/cli/Main.java index 5501bbf72..bef54f8fc 100644 --- a/convex-cli/src/main/java/convex/cli/Main.java +++ b/convex-cli/src/main/java/convex/cli/Main.java @@ -99,8 +99,14 @@ public class Main extends ACommand { @Option(names = { "-n","--noninteractive" }, scope = ScopeType.INHERIT, - description = "Specify to disable interactive prompts") + description = "Specify to disable interactive prompts. Intended for scripts.") private boolean nonInteractive; + + @Option(names = { "--no-color" }, + scope = ScopeType.INHERIT, + defaultValue = "${env:NO_COLOR}", + description = "Suppress ANSI colour output. Can also stop with NO_COLOR uenviornment variable") + private boolean noColour; @Option(names = { "-v","--verbose" }, scope = ScopeType.INHERIT, @@ -204,7 +210,8 @@ public int handleExecutionException(Exception ex, CommandLine commandLine, Parse PrintWriter err = commandLine.getErr(); if (ex instanceof CLIError) { CLIError ce = (CLIError) ex; - String msg=Coloured.red(ce.getMessage()); + String msg=ce.getMessage(); + msg=noColour?msg:Coloured.red(msg); err.println(msg); Throwable cause = ce.getCause(); if (cause != null) { @@ -503,12 +510,12 @@ public String loadFileAsString(String fname) { } - public void informSuccess(String msg) { - inform(1, Coloured.green(msg)); + public void informSuccess(String message) { + inform(1, noColour?message:Coloured.green(message)); } public void inform(String message) { - inform(1, Coloured.yellow(message)); + inform(1, noColour?message:Coloured.yellow(message)); } private void inform(int level, String message) { diff --git a/convex-cli/src/main/java/convex/cli/client/Query.java b/convex-cli/src/main/java/convex/cli/client/Query.java index 9faafd093..59e82d0e3 100644 --- a/convex-cli/src/main/java/convex/cli/client/Query.java +++ b/convex-cli/src/main/java/convex/cli/client/Query.java @@ -47,7 +47,7 @@ public void run() { } catch (IOException e) { throw new CLIError("IO Error executing query",e); } catch (TimeoutException e) { - throw new CLIError("Query timed out"); + throw new CLIError("Query timed out. Perhaps there is a network problem, or the host is not an operational Convex peer?"); } } } diff --git a/convex-core/src/main/java/etch/Etch.java b/convex-core/src/main/java/etch/Etch.java index de61be936..6343ce1dc 100644 --- a/convex-core/src/main/java/etch/Etch.java +++ b/convex-core/src/main/java/etch/Etch.java @@ -604,7 +604,7 @@ synchronized void close() { data.close(); - log.debug("Etch closed on file: "+ getFileName() +" with data length: "+dataLength); + log.trace("Etch closed on file: "+ getFileName() +" with data length: "+dataLength); } catch (IOException e) { log.error("Error closing Etch file: "+file); } diff --git a/convex-peer/src/main/java/convex/net/Connection.java b/convex-peer/src/main/java/convex/net/Connection.java index 437c05d24..c067e2468 100644 --- a/convex-peer/src/main/java/convex/net/Connection.java +++ b/convex-peer/src/main/java/convex/net/Connection.java @@ -206,7 +206,7 @@ public static Connection connect(InetSocketAddress socketAddress, Consumer