refactor: [cmd] thinking in output

上级 b8d317e2
......@@ -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()
......
......@@ -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()
}
......@@ -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
......@@ -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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册