diff --git a/cobra/cmd/root.go b/cobra/cmd/root.go index 624c717..97f404b 100644 --- a/cobra/cmd/root.go +++ b/cobra/cmd/root.go @@ -36,8 +36,8 @@ to quickly create a Cobra application.`, ) // Execute executes the root command. -func Execute() { - rootCmd.Execute() +func Execute() error { + return rootCmd.Execute() } func init() { diff --git a/cobra/main.go b/cobra/main.go index c3a9d9c..8add69a 100644 --- a/cobra/main.go +++ b/cobra/main.go @@ -13,8 +13,18 @@ package main -import "github.com/spf13/cobra/cobra/cmd" +import ( + "os" + + "github.com/spf13/cobra/cobra/cmd" +) func main() { - cmd.Execute() + if err := runMain(); err != nil { + os.Exit(1) + } +} + +func runMain() error { + return cmd.Execute() }