diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index c8253085c..1647cf010 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -1,7 +1,7 @@ { "ImportPath": "github.com/asteris-llc/converge", "GoVersion": "go1.6", - "GodepVersion": "v70", + "GodepVersion": "v74", "Packages": [ "./..." ], @@ -16,6 +16,10 @@ "Comment": "v0.10.0-16-gcd7d1bb", "Rev": "cd7d1bbe41066b6c1f19780f895901052150a575" }, + { + "ImportPath": "github.com/acmacalister/skittles", + "Rev": "8f7bde0f0de4cb42c1e8db861e67627558e97019" + }, { "ImportPath": "github.com/davecgh/go-spew/spew", "Rev": "5215b55f46b2b919f50a1df0eaa5886afe4e3b3d" diff --git a/cmd/apply.go b/cmd/apply.go index 26f6e2bef..842f7c918 100644 --- a/cmd/apply.go +++ b/cmd/apply.go @@ -22,6 +22,7 @@ import ( "golang.org/x/net/context" "github.com/Sirupsen/logrus" + "github.com/acmacalister/skittles" "github.com/asteris-llc/converge/exec" "github.com/asteris-llc/converge/load" "github.com/spf13/cobra" @@ -97,7 +98,16 @@ var applyCmd = &cobra.Command{ } } - fmt.Printf("\nApply complete. %d changes, %d successful, %d failed\n", counts.results, counts.success, counts.failures) + // summarize the changes for the user + summary := fmt.Sprintf("\nApply complete. %d changes, %d successful, %d failed\n", counts.results, counts.success, counts.failures) + if UseColor() { + if counts.failures > 0 { + summary = skittles.Red(summary) + } else { + summary = skittles.Green(summary) + } + } + fmt.Print(summary) if counts.failures > 0 { os.Exit(1) diff --git a/cmd/plan.go b/cmd/plan.go index 679311746..eca653a6a 100644 --- a/cmd/plan.go +++ b/cmd/plan.go @@ -21,6 +21,7 @@ import ( "golang.org/x/net/context" "github.com/Sirupsen/logrus" + "github.com/acmacalister/skittles" "github.com/asteris-llc/converge/exec" "github.com/asteris-llc/converge/load" "github.com/spf13/cobra" @@ -80,7 +81,16 @@ var planCmd = &cobra.Command{ } } - fmt.Printf("\nPlan complete. %d checks, %d will change\n", counts.results, counts.changes) + // summarize the potential changes for the user + summary := fmt.Sprintf("\nPlan complete. %d checks, %d will change\n", counts.results, counts.changes) + if UseColor() { + if counts.changes > 0 { + summary = skittles.Yellow(summary) + } else { + summary = skittles.Green(summary) + } + } + fmt.Print(summary) } }, } diff --git a/cmd/util.go b/cmd/util.go index c8a000a24..7e0515c0c 100644 --- a/cmd/util.go +++ b/cmd/util.go @@ -15,6 +15,8 @@ package cmd import ( + "runtime" + "github.com/Sirupsen/logrus" "github.com/spf13/pflag" "github.com/spf13/viper" @@ -26,3 +28,11 @@ func viperBindPFlags(flags *pflag.FlagSet) { logrus.WithError(err).Fatal("could not bind flags") } } + +// UseColor tells us whether or not to print colors using ANSI escape sequences +// based on the following: 1. If we're in a color terminal 2. If the user has +// specified the `nocolor` option (deduced via Viper) 3. If we're on Windows. +func UseColor() bool { + isColorTerminal := logrus.IsTerminal() && (runtime.GOOS != "windows") + return !viper.GetBool("nocolor") && isColorTerminal +} diff --git a/cmd/util_test.go b/cmd/util_test.go new file mode 100644 index 000000000..122fa7676 --- /dev/null +++ b/cmd/util_test.go @@ -0,0 +1,26 @@ +// Copyright © 2016 Asteris, LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package cmd_test + +import ( + "testing" + + "github.com/asteris-llc/converge/cmd" + "github.com/stretchr/testify/assert" +) + +func TestUseColor(t *testing.T) { + assert.NotPanics(t, func() { cmd.UseColor() }) +}