-
Notifications
You must be signed in to change notification settings - Fork 0
/
root.go
56 lines (49 loc) · 1.15 KB
/
root.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package cmd
import (
"errors"
"github.com/spf13/cobra"
"github.com/spiegel-im-spiegel/gocli/exitcode"
"github.com/spiegel-im-spiegel/gocli/rwi"
"runtime"
)
var (
cui = rwi.New()
)
func newRootCmd(ui *rwi.RWI, args []string) *cobra.Command {
cui = ui
rootCmd := &cobra.Command{
Use: "cloud-function-avoid-cli",
Short: "Custom Claims",
Long: "Custom Claims (detail)",
RunE: func(cmd *cobra.Command, args []string) error {
return errors.New("no command")
},
}
rootCmd.SetArgs(args)
rootCmd.SetOutput(ui.ErrorWriter())
rootCmd.AddCommand(newClaimsCmd())
return rootCmd
}
//Execute is called from main function
func Execute(ui *rwi.RWI, args []string) (exit exitcode.ExitCode) {
defer func() {
//panic hundling
if r := recover(); r != nil {
cui.OutputErrln("Panic:", r)
for depth := 0; ; depth++ {
pc, src, line, ok := runtime.Caller(depth)
if !ok {
break
}
cui.OutputErrln(" ->", depth, ":", runtime.FuncForPC(pc).Name(), ":", src, ":", line)
}
exit = exitcode.Abnormal
}
}()
//execution
exit = exitcode.Normal
if err := newRootCmd(ui, args).Execute(); err != nil {
exit = exitcode.Abnormal
}
return
}