hashicorp / levant

An open source templating and deployment tool for HashiCorp Nomad jobs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unable to pipe output to grep / jq

srisch opened this issue · comments

Description
Piping output from levant into a program doesn't work, everything goes to stderr.

Plan any job with the following command on linux and you can see that it's output is going to stderr. I'd expect you could grep for a string change, or pipe json results into jq which makes reading large jobs easier.

levant plan somejob.nomad | grep "a string you expect" - Grep doesn't work
levant plan somejob.nomad |& grep "a string you expect" - Grep does work as stderr is combined into stdout

This helpful command will show stderr vs stdout
{ { levant plan yourjob.nomad; } 2>&3 | sed 's/^/STDOUT: /'; } 3>&1 1>&2 | sed 's/^/STDERR: /'

The issue appears to be within the os.Stdout.Fd check as when you pipe levant's output this check returns false causing everything to go to stderr.

if isatty.IsTerminal(os.Stdout.Fd()) ||
	isatty.IsCygwinTerminal(os.Stdout.Fd()) {
	logWriter = conswriter.GetTerminal()
} else {
	logWriter = os.Stderr
}

Output of levant version:

Levant v0.3.3-dev