Merge remote-tracking branch 'origin/master' into issue-update

This commit is contained in:
Corey Johnson 2019-11-18 11:09:00 -08:00
parent 75a3496bf1
commit e5af5be940
23 changed files with 1354 additions and 65 deletions

View file

@ -1,24 +1,39 @@
package utils
import "github.com/mgutz/ansi"
import (
"github.com/mattn/go-isatty"
"github.com/mgutz/ansi"
"os"
)
var Black = ansi.ColorFunc("black")
var White = ansi.ColorFunc("white")
func makeColorFunc(color string) func(string) string {
return func(arg string) string {
output := arg
if isatty.IsTerminal(os.Stdout.Fd()) {
output = ansi.Color(color+arg+ansi.Reset, "")
}
func Gray(arg string) string {
return ansi.Color(ansi.LightBlack+arg, "")
return output
}
}
var Red = ansi.ColorFunc("red")
var Green = ansi.ColorFunc("green")
var Yellow = ansi.ColorFunc("yellow")
var Blue = ansi.ColorFunc("blue")
var Magenta = ansi.ColorFunc("magenta")
var Cyan = ansi.ColorFunc("cyan")
var Black = makeColorFunc(ansi.Black)
var White = makeColorFunc(ansi.White)
var Magenta = makeColorFunc(ansi.Magenta)
var Cyan = makeColorFunc(ansi.Cyan)
var Red = makeColorFunc(ansi.Red)
var Yellow = makeColorFunc(ansi.Yellow)
var Blue = makeColorFunc(ansi.Blue)
var Green = makeColorFunc(ansi.Green)
var Gray = makeColorFunc(ansi.LightBlack)
func Bold(arg string) string {
// This is really annoying. If you just define Bold as ColorFunc("+b") it will properly bold but
// will not use the default color, resulting in black and probably unreadable text. This forces
// the default color before bolding.
return ansi.Color(ansi.DefaultFG+arg, "+b")
output := arg
if isatty.IsTerminal(os.Stdout.Fd()) {
// This is really annoying. If you just define Bold as ColorFunc("+b") it will properly bold but
// will not use the default color, resulting in black and probably unreadable text. This forces
// the default color before bolding.
output = ansi.Color(ansi.DefaultFG+arg+ansi.Reset, "+b")
}
return output
}

View file

@ -38,6 +38,9 @@ func (c cmdWithStderr) Output() ([]byte, error) {
if os.Getenv("DEBUG") != "" {
fmt.Fprintf(os.Stderr, "%v\n", c.Cmd.Args)
}
if c.Cmd.Stderr != nil {
return c.Cmd.Output()
}
errStream := &bytes.Buffer{}
c.Cmd.Stderr = errStream
out, err := c.Cmd.Output()
@ -51,6 +54,9 @@ func (c cmdWithStderr) Run() error {
if os.Getenv("DEBUG") != "" {
fmt.Fprintf(os.Stderr, "%v\n", c.Cmd.Args)
}
if c.Cmd.Stderr != nil {
return c.Cmd.Run()
}
errStream := &bytes.Buffer{}
c.Cmd.Stderr = errStream
err := c.Cmd.Run()