forked from mirror/cobra
Add idiomatic handling of go error in distinct main func
This commit is contained in:
parent
af29f95b81
commit
9552679939
|
@ -36,8 +36,8 @@ to quickly create a Cobra application.`,
|
||||||
)
|
)
|
||||||
|
|
||||||
// Execute executes the root command.
|
// Execute executes the root command.
|
||||||
func Execute() {
|
func Execute() error {
|
||||||
rootCmd.Execute()
|
return rootCmd.Execute()
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
|
@ -13,8 +13,18 @@
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import "github.com/spf13/cobra/cobra/cmd"
|
import (
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/spf13/cobra/cobra/cmd"
|
||||||
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
cmd.Execute()
|
if err := runMain(); err != nil {
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func runMain() error {
|
||||||
|
return cmd.Execute()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue