Skip to content

Commit

Permalink
Merge pull request #177 from ngageoint/issue176
Browse files Browse the repository at this point in the history
Closes #176 added red text for stderr output
  • Loading branch information
gisjedi authored Sep 7, 2018
2 parents c24e023 + 0fb8e92 commit 7b298b6
Show file tree
Hide file tree
Showing 14 changed files with 1,923 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ temp-*

# test manifests updated during tests
testdata/complete/seed.manifest.json

# useless OSX Finder files
*.DS_Store
4 changes: 3 additions & 1 deletion commands/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ import (
"syscall"
"time"

"github.com/fatih/color"
"github.com/ngageoint/seed-cli/constants"
"github.com/ngageoint/seed-cli/streampainter"
common_const "github.com/ngageoint/seed-common/constants"
"github.com/ngageoint/seed-common/objects"
"github.com/ngageoint/seed-common/util"
Expand Down Expand Up @@ -157,7 +159,7 @@ func DockerRun(imageName, outputDir, metadataSchema string, inputs, json, settin
dockerRun := exec.Command("docker", dockerArgs...)
var errs bytes.Buffer
if !quiet {
dockerRun.Stderr = io.MultiWriter(&errs, os.Stderr)
dockerRun.Stderr = io.MultiWriter(&errs, streampainter.NewStreamPainter(color.FgRed))
dockerRun.Stdout = os.Stderr
}

Expand Down
24 changes: 24 additions & 0 deletions streampainter/streampainter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package streampainter

import (
"os"

"github.com/fatih/color"
)

type StreamPainter struct {
paintColor color.Attribute
}

/*
* NewStreamPainter returns new streampainter
*/
func NewStreamPainter(textColor color.Attribute) *StreamPainter {
return &StreamPainter{textColor}
}

func (w *StreamPainter) Write(p []byte) (int, error) {
n := len(p)
color.New(w.paintColor).Fprintf(os.Stderr, string(p[:n]))
return n, nil
}
18 changes: 18 additions & 0 deletions streampainter/streampainter_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package streampainter

import (
"testing"

"github.com/fatih/color"
)

func TestStreamPainter(t *testing.T) {
writer := NewStreamPainter(color.FgRed)
_, err := writer.Write([]byte("should be in red"))
if err != nil {
t.Errorf("Error should be 'nil', but was %v", err.Error())
}
if writer.paintColor != color.FgRed {
t.Errorf("Assigned color expected FgRed, but was %v", writer.paintColor)
}
}
6 changes: 6 additions & 0 deletions vendor/github.com/fatih/color/.travis.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions vendor/github.com/fatih/color/LICENSE.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

179 changes: 179 additions & 0 deletions vendor/github.com/fatih/color/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 7b298b6

Please sign in to comment.