Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented use of 3 variables instead of a single #18

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,27 @@ $ gotest -v github.com/rakyll/hey
```
![go test output](https://i.imgur.com/udjWuZx.gif)

gotest comes with many colors! Configure the color of the output by setting the following env variable:
gotest comes with many colors! Configure the color of the output by setting the following environment variables:

- `GOTEST_FAIL`
- `GOTEST_PASS`
- `GOTEST_SKIP`

Alternatively you can use a single environment supporting a list of colors, in the order: fail and pass.

```
$ GOTEST_PALETTE="magenta,white"
```

The output will have magenta for failed cases, white for success.
Available colors: black, hiblack, red, hired, green, higreen, yellow, hiyellow, blue, hiblue, magenta, himagenta, cyan, hicyan, white, hiwhite.

Do note that the individually set environment variables take precedence over the palette variable

For the setting:

```
$ GOTEST_PASS="hiblue" GOTEST_PALETTE="magenta,white"
```

The output will have magenta for failed cases, hiblue for success.
64 changes: 49 additions & 15 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,21 @@ import (
"github.com/fatih/color"
)

const (
paletteEnv = "GOTEST_PALETTE"
failEnv = "GOTEST_FAIL_COLOR"
passEnv = "GOTEST_PASS_COLOR"
skipEnv = "GOTEST_SKIP_COLOR"
)

var (
pass = color.FgGreen
skip = color.FgYellow
fail = color.FgHiRed
)

const paletteEnv = "GOTEST_PALETTE"

func main() {
setPalette()
parseEnvAndSetPalette()
enableOnCI()
os.Exit(gotest(os.Args[1:]))
}
Expand Down Expand Up @@ -144,20 +149,49 @@ func enableOnCI() {
}
}

func setPalette() {
func parseEnvAndSetPalette() {
parsePaletteEnv()
parseColorEnvs()
}

func parsePaletteEnv() {

v := os.Getenv(paletteEnv)
if v == "" {
return
}
vals := strings.Split(v, ",")
if len(vals) != 2 {
return
}
if c, ok := colors[vals[0]]; ok {
fail = c

if v != "" {
vals := strings.Split(v, ",")
states := []color.Attribute{fail, pass, skip}
for i := range vals {
if c, ok := colors[vals[i]]; ok {
states[i] = color.Attribute(c)
}
}

fail = states[0]
pass = states[1]
skip = states[2]
}
if c, ok := colors[vals[1]]; ok {
pass = c
}

func parseColorEnvs() {

envArray := [3]string{skipEnv, failEnv, passEnv}

for _, e := range envArray {
v := os.Getenv(e)
if v == "" {
continue
}
if c, ok := colors[v]; ok {
switch e {
case failEnv:
fail = c
case passEnv:
pass = c
case skipEnv:
skip = c
}
}
}
}

Expand Down