mirror of
https://github.com/spf13/cobra
synced 2024-11-24 14:47:12 +00:00
Add idiomatic handling of go error in distinct main func
This commit is contained in:
parent
af29f95b81
commit
9552679939
2 changed files with 14 additions and 4 deletions
|
@ -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() {
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue