CLI tasks/scripts, logging, UI and generally complexity

Brut, like many frameworks, relies on a CLI-based workflow. Most of these in Brut are scripts, e.g. brut test to run tests or brut db migrate to apply DB migrations.

My initial implementation was geared around having each script output what it was doing. I was always frustrated by Rails rake tasks producing very little useful output, especially in error cases.

The downside is that this produces a massive amount of output. So, I revised everything to work like so:

  • default output is nicely formatted, “no news is good news” type of stuff, using ANSI escape codes and trying to have a nice experience with little output by default
  • a log file is created that has all the information in it that was previously output to the terminal
  • a flag on all apps allows you to see the log output on standard output

The result is not great, to be honest. Any time there is an error, I print out the location of the log so the user knows where to find more, though often there isn’t any more. I also have to carefully capture the stdout/stdin of all subprocesses being run.

Further, lots of gems produce log messages by default, and controlling that is often difficult. For example, Honeybadger will always produce a message that it’s in dev mode just by being required. You have to set HONEYBADGER_LOGGING_LEVEL to error before you require it. Ugh.

Part of me wants to just return to the wall of text output as that is the easiest to understand what’s going on. But it still sucks.

Anyone have examples of CLI scripts that a) produce nice output on success cases, b) clearly show errors on failure cases, and c) do not throw away information to make (a) and (b) happen?

(I’m not talking about persisted/interactice TUIs - just about scripts that do a thing and report what happened.)

1 Like