Improve config dump output
authorMikael Berthe <mikael@lilotux.net>
Wed, 10 May 2017 19:48:09 +0200
changeset 114 590c9dd7328e
parent 113 2e411da68fd3
child 115 8ae0dda7756d
Improve config dump output Do not display instructions when stdout is not a TTY.
cmd/config.go
--- a/cmd/config.go	Wed May 10 14:11:13 2017 +0200
+++ b/cmd/config.go	Wed May 10 19:48:09 2017 +0200
@@ -8,6 +8,7 @@
 import (
 	"os"
 
+	"github.com/mattn/go-isatty"
 	"github.com/spf13/cobra"
 	"github.com/spf13/viper"
 
@@ -89,9 +90,11 @@
 		if cfile == "" {
 			cfile = defaultConfigFile
 		}
-		errPrint("You can copy the following lines into a configuration file.")
-		errPrint("E.g. %s -i INSTANCE -L USERNAME -P PASS config dump > %s", AppName, cfile)
-		errPrint(" or  %s -i INSTANCE oauth2 > %s\n", AppName, cfile)
+		if isatty.IsTerminal(os.Stdout.Fd()) {
+			errPrint("You can copy the following lines into a configuration file.")
+			errPrint("E.g. %s -i INSTANCE -L USERNAME -P PASS config dump > %s", AppName, cfile)
+			errPrint(" or  %s -i INSTANCE oauth2 > %s\n", AppName, cfile)
+		}
 		pOptions := printer.Options{"template": configurationTemplate}
 		p, err = printer.NewPrinterTemplate(pOptions)
 	} else {