Skip to content

Commit cd41ee9

Browse files
committed
More CLI output improvements, add --no-color option
1 parent 91d0509 commit cd41ee9

File tree

4 files changed

+19
-12
lines changed

4 files changed

+19
-12
lines changed

convex-cli/src/main/java/convex/cli/Main.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,14 @@ public class Main extends ACommand {
9999

100100
@Option(names = { "-n","--noninteractive" },
101101
scope = ScopeType.INHERIT,
102-
description = "Specify to disable interactive prompts")
102+
description = "Specify to disable interactive prompts. Intended for scripts.")
103103
private boolean nonInteractive;
104+
105+
@Option(names = { "--no-color" },
106+
scope = ScopeType.INHERIT,
107+
defaultValue = "${env:NO_COLOR}",
108+
description = "Suppress ANSI colour output. Can also stop with NO_COLOR uenviornment variable")
109+
private boolean noColour;
104110

105111
@Option(names = { "-v","--verbose" },
106112
scope = ScopeType.INHERIT,
@@ -204,7 +210,8 @@ public int handleExecutionException(Exception ex, CommandLine commandLine, Parse
204210
PrintWriter err = commandLine.getErr();
205211
if (ex instanceof CLIError) {
206212
CLIError ce = (CLIError) ex;
207-
String msg=Coloured.red(ce.getMessage());
213+
String msg=ce.getMessage();
214+
msg=noColour?msg:Coloured.red(msg);
208215
err.println(msg);
209216
Throwable cause = ce.getCause();
210217
if (cause != null) {
@@ -503,12 +510,12 @@ public String loadFileAsString(String fname) {
503510
}
504511

505512

506-
public void informSuccess(String msg) {
507-
inform(1, Coloured.green(msg));
513+
public void informSuccess(String message) {
514+
inform(1, noColour?message:Coloured.green(message));
508515
}
509516

510517
public void inform(String message) {
511-
inform(1, Coloured.yellow(message));
518+
inform(1, noColour?message:Coloured.yellow(message));
512519
}
513520

514521
private void inform(int level, String message) {

convex-cli/src/main/java/convex/cli/client/Query.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public void run() {
4747
} catch (IOException e) {
4848
throw new CLIError("IO Error executing query",e);
4949
} catch (TimeoutException e) {
50-
throw new CLIError("Query timed out");
50+
throw new CLIError("Query timed out. Perhaps there is a network problem, or the host is not an operational Convex peer?");
5151
}
5252
}
5353
}

convex-core/src/main/java/etch/Etch.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ synchronized void close() {
604604

605605
data.close();
606606

607-
log.debug("Etch closed on file: "+ getFileName() +" with data length: "+dataLength);
607+
log.trace("Etch closed on file: "+ getFileName() +" with data length: "+dataLength);
608608
} catch (IOException e) {
609609
log.error("Error closing Etch file: "+file);
610610
}

convex-peer/src/main/java/convex/net/Connection.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ public static Connection connect(InetSocketAddress socketAddress, Consumer<Messa
206206

207207
Connection pc = create(clientChannel, receiveAction, store, trustedPeerKey);
208208
pc.startClientListening();
209-
log.debug("Connect succeeded for host: {}", socketAddress);
209+
log.trace("Connect succeeded for host: {}", socketAddress);
210210
return pc;
211211
}
212212

@@ -554,7 +554,7 @@ private static void ensureSelectorLoop() {
554554
private static Runnable selectorLoop = new Runnable() {
555555
@Override
556556
public void run() {
557-
log.debug("Client selector loop starting...");
557+
log.trace("Client selector loop starting...");
558558
while (true) {
559559
try {
560560
selector.select(300);
@@ -583,7 +583,7 @@ public void run() {
583583
log.trace("Unexpected IOException, cancelling key: {}", e);
584584
key.cancel();
585585
} catch (CancelledKeyException e) {
586-
log.debug("Cancelled key");
586+
log.trace("Cancelled key");
587587
}
588588
}
589589
} catch (Exception t) {
@@ -610,12 +610,12 @@ protected static void selectRead(SelectionKey key) throws IOException {
610610
int n = conn.handleChannelRecieve();
611611
if (n<0) {
612612
// Deregister interest in reading if EOS
613-
log.debug("Cancelled Key due to EOS");
613+
log.trace("Cancelled Key due to EOS");
614614
key.cancel();
615615
}
616616
// log.finest("Received bytes: " + n);
617617
} catch (ClosedChannelException e) {
618-
log.debug("Channel closed from: {}", conn.getRemoteAddress());
618+
log.trace("Channel closed from: {}", conn.getRemoteAddress());
619619
key.cancel();
620620
} catch (BadFormatException e) {
621621
log.warn("Cancelled connection to Peer: Bad data format from: " + conn.getRemoteAddress() + " "

0 commit comments

Comments
 (0)