diff --git a/cmd/coca_test.go b/cmd/coca_test.go index 059bf9d63eba696ff50621ed16ae436e38a90c4c..1a4e85c03724c6d05cdf1dd1cd6a796a8e7454e4 100644 --- a/cmd/coca_test.go +++ b/cmd/coca_test.go @@ -42,7 +42,7 @@ func executeActionCommandC(cmd string) (*cobra.Command, string, error) { } buf := new(bytes.Buffer) - rootCmd.SetOutput(buf) + rootCmd.SetOut(buf) rootCmd.SetArgs(args) c, err := rootCmd.ExecuteC() diff --git a/cmd/root.go b/cmd/root.go index 5c2c643d2779a677a4cf61f57b03a7806ff27c52..8d1549a097231451b5a917fca48460d33d457446 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -2,9 +2,11 @@ package cmd import ( "github.com/spf13/cobra" + "os" ) var ( + output = os.Stdout rootCmd = &cobra.Command{ Use: "coca", Short: "A generator for Cobra based Applications", @@ -13,6 +15,6 @@ var ( ) func Execute() error { + rootCmd.SetOut(output) return rootCmd.Execute() } - diff --git a/cmd/testdata/version.txt b/cmd/testdata/version.txt new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/cmd/version.go b/cmd/version.go index 0fd66b75350cb2d2c7f42c704c8c26c6f711426a..38e353b4e396e102c3a4c27582b402149cc4ec44 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -7,6 +7,7 @@ import ( ) func init() { + versionCmd.SetOut(output) rootCmd.AddCommand(versionCmd) } @@ -14,6 +15,6 @@ var versionCmd = &cobra.Command{ Use: "version", Short: "version", Run: func(cmd *cobra.Command, args []string) { - fmt.Println("Coca Version: " + config.VERSION + " -- HEAD") + fmt.Fprintf(output, "Coca Version: " + config.VERSION + " -- HEAD \n") }, } \ No newline at end of file diff --git a/cmd/version_test.go b/cmd/version_test.go index ad28fbb8a024009ad7e23f05aae42bb46cd4f7f5..cc2165e0caa4ca0acb76169f51e777a55b75456e 100644 --- a/cmd/version_test.go +++ b/cmd/version_test.go @@ -8,7 +8,7 @@ func TestVersion(t *testing.T) { tests := []cmdTestCase{{ name: "version", cmd: "version", - golden: "", + golden: "testdata/version.txt", }} runTestCmd(t, tests) } \ No newline at end of file