Skip to content

Commit

Permalink
More CLI output improvements, add --no-color option
Browse files Browse the repository at this point in the history
  • Loading branch information
mikera committed Jul 30, 2024
1 parent 91d0509 commit cd41ee9
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 12 deletions.
17 changes: 12 additions & 5 deletions convex-cli/src/main/java/convex/cli/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion convex-cli/src/main/java/convex/cli/client/Query.java
Original file line number Diff line number Diff line change
Expand Up @@ -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?");
}
}
}
2 changes: 1 addition & 1 deletion convex-core/src/main/java/etch/Etch.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
10 changes: 5 additions & 5 deletions convex-peer/src/main/java/convex/net/Connection.java
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public static Connection connect(InetSocketAddress socketAddress, Consumer<Messa

Connection pc = create(clientChannel, receiveAction, store, trustedPeerKey);
pc.startClientListening();
log.debug("Connect succeeded for host: {}", socketAddress);
log.trace("Connect succeeded for host: {}", socketAddress);
return pc;
}

Expand Down Expand Up @@ -554,7 +554,7 @@ private static void ensureSelectorLoop() {
private static Runnable selectorLoop = new Runnable() {
@Override
public void run() {
log.debug("Client selector loop starting...");
log.trace("Client selector loop starting...");
while (true) {
try {
selector.select(300);
Expand Down Expand Up @@ -583,7 +583,7 @@ public void run() {
log.trace("Unexpected IOException, cancelling key: {}", e);
key.cancel();
} catch (CancelledKeyException e) {
log.debug("Cancelled key");
log.trace("Cancelled key");
}
}
} catch (Exception t) {
Expand All @@ -610,12 +610,12 @@ protected static void selectRead(SelectionKey key) throws IOException {
int n = conn.handleChannelRecieve();
if (n<0) {
// Deregister interest in reading if EOS
log.debug("Cancelled Key due to EOS");
log.trace("Cancelled Key due to EOS");
key.cancel();
}
// log.finest("Received bytes: " + n);
} catch (ClosedChannelException e) {
log.debug("Channel closed from: {}", conn.getRemoteAddress());
log.trace("Channel closed from: {}", conn.getRemoteAddress());
key.cancel();
} catch (BadFormatException e) {
log.warn("Cancelled connection to Peer: Bad data format from: " + conn.getRemoteAddress() + " "
Expand Down

0 comments on commit cd41ee9

Please sign in to comment.