diff --git a/cmd/root.go b/cmd/root.go index 245a647..1535bad 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -6,6 +6,7 @@ package cmd import ( "github.com/AlecAivazis/survey/v2" + "github.com/create-go-app/cli/v3/pkg/cgapp" "github.com/create-go-app/cli/v3/pkg/registry" "github.com/spf13/cobra" ) @@ -48,6 +49,11 @@ frontend (JavaScript, TypeScript) and deploy automation A helpful documentation and next steps -> https://create-go.app/`, } +func init() { + rootCmd.SetOut(cgapp.Stdout) + rootCmd.SetErr(cgapp.Stderr) +} + // Execute adds all child commands to the root command and sets flags appropriately. // This is called by main.main(). It only needs to happen once to the rootCmd. func Execute() { diff --git a/pkg/cgapp/utils.go b/pkg/cgapp/utils.go index 3d967f1..4ca5d75 100644 --- a/pkg/cgapp/utils.go +++ b/pkg/cgapp/utils.go @@ -7,9 +7,15 @@ package cgapp import ( "fmt" "time" + + "github.com/mattn/go-colorable" +) + +var ( + Stdout = colorable.NewColorableStdout() + Stderr = colorable.NewColorableStderr() ) -// ShowMessage function for send message to output. func ShowMessage(level, text string, startWithNewLine, endWithNewLine bool) { // Define variables. var startLine, endLine string @@ -22,12 +28,12 @@ func ShowMessage(level, text string, startWithNewLine, endWithNewLine bool) { endLine = "\n" // set a new line } - fmt.Println(startLine + colorizeLevel(level) + text + endLine) + fmt.Fprintln(Stdout, startLine+colorizeLevel(level)+text+endLine) } // ShowError function for send error message to output. func ShowError(text string) error { - return fmt.Errorf(colorizeLevel("error") + text) + return fmt.Errorf("%s", colorizeLevel("error")+text) } // CalculateDurationTime func to calculate duration time.