bids-validator icon indicating copy to clipboard operation
bids-validator copied to clipboard

do not ANSI color --version, especially if output is not interactive TTY

Open yarikoptic opened this issue 2 months ago • 4 comments

since I might use it in filename but

Image

and I end up with

$> bvv=$(bids-validator-deno --version | awk '{{print $2;}}'); mkdir derivatives/; bids-validator-deno --json -o derivatives/bids-validator-$bvv.json .

$> ls -l derivatives/
total 84
84 -rw-r--r-- 1 yarick jblab 84372 Oct  1 11:56 'bids-validator-'$'\033''[94m2.1.1'$'\033''[39m.json'

yarikoptic avatar Oct 01 '25 15:10 yarikoptic

That's supposed to be detected automatically. You can force it with NO_COLOR=1.

effigies avatar Oct 01 '25 16:10 effigies

Looks like we can use Deno.stdout.isTerminal() to make sure that colors are turned off.

󰅂 echo 'Deno.stdout.isTerminal()' | deno -q | cat
false
󰅂 echo 'Deno.stdout.isTerminal()' | deno -q      
true

effigies avatar Oct 01 '25 16:10 effigies

It's silly but using the short form of the flag should produce what you're looking for.

$ ./local-run -V
2.1.1

Version flag is currently handled automatically by the library Cliffy.

rwblair avatar Oct 01 '25 18:10 rwblair

ha, cool @rwblair , I will try to remember . Comes a little unexpected since no such difference is noted in

-V, --version                          - Show the version number for this program.

yarikoptic avatar Oct 02 '25 19:10 yarikoptic