Skip to content

Add color to get workflow output

Current situation

It's sometime a bit hard to distinguish executed commands outputs from orchestrator log when using opentf-ctl get workflow ... in 'regular' mode (that is, not yaml or json output, not redirected to a file, ...).

Desired outcome

Some colors in the run command outputs (say, green by default) and errors (say, red by default).

It should be configurable, and should follow the 'common' environment variables conventions:

  • if FORCE_COLOR is set to 1, on, true, or yes, then color should be enabled.
  • if NO_COLOR is set to 1, on, true, or yes, then color should be disabled.
  • if OPENTF_COLORS is set to 1, on, true, or yes, the color should be enabled.

OPENTF_COLORS takes precedence over NO_COLOR, which in turn takes precedence over FORCE_COLOR.

Disabled on a non-tty output (say, a regular file) by default, enabled otherwise. Use above environment variables to choose otherwise.

Colors are specified in a format similar to LS_COLORS.

Colors that can be defined:

name area
pre prefix
inv invalid prefix
req environment request
rel environment release
idx nested indent
run running command
grp group event
ntf notification
att attachment
out environment output
ret running command non-zero return code
err execution error
ttl title
ns namespace
fun running function or bundle
sta workflow status
rsn workflow failure reason

In other words, if your colors entry is out=32:err=31:grp=4;93:pre=97;105:ns=1:idx=7, environment output will be in green, errors in red, group events in underlined orange, prefix in bright white on magenta, namespace in bright white, and indent level in reverse.

There is one optional colors entry per user config. If none is defined, green for out and red for err are the defaults.

Edited by Martin Lafaix