/
root.go
52 lines (41 loc) · 1016 Bytes
/
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
package cmd
import (
"context"
"os"
"github.com/caarlos0/log"
"github.com/spf13/cobra"
"github.com/ilaif/gh-prx/pkg/cmd/setup"
)
func Execute(version string) {
rootCmd := NewRootCmd(version)
ctx := context.Background()
if err := rootCmd.ExecuteContext(ctx); err != nil {
log.WithError(err).Error("Command failed")
os.Exit(1)
}
}
func NewRootCmd(version string) *cobra.Command {
var debug bool
rootCmd := &cobra.Command{
Use: "prx",
Short: "Extended Git & GitHub CLI flows",
SilenceUsage: true,
SilenceErrors: true,
Version: version,
PersistentPreRun: func(_ *cobra.Command, _ []string) {
log.SetLevel(log.InfoLevel)
log.DecreasePadding() // remove the default padding
if debug {
log.Info("Debug logs enabled")
log.SetLevel(log.DebugLevel)
}
},
}
rootCmd.PersistentFlags().BoolVar(&debug, "debug", false, "verbose logging")
rootCmd.AddCommand(
setup.NewSetupCmd(),
NewCreateCmd(),
NewCheckoutNewCmd(),
)
return rootCmd
}