-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathroot.go
More file actions
76 lines (60 loc) · 1.64 KB
/
root.go
File metadata and controls
76 lines (60 loc) · 1.64 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package cmd
import (
"errors"
"fmt"
"os"
"github.com/github/gh-stack/internal/config"
"github.com/spf13/cobra"
)
func RootCmd() *cobra.Command {
cfg := config.New()
root := &cobra.Command{
Use: "stack <command>",
Short: "Manage stacked branches and pull requests",
Long: "Create, navigate, and manage stacks of branches and pull requests.",
Version: Version,
SilenceUsage: true,
SilenceErrors: true,
}
root.SetVersionTemplate("gh stack version {{.Version}}\n")
root.SetOut(cfg.Out)
root.SetErr(cfg.Err)
// Local operations
root.AddCommand(InitCmd(cfg))
root.AddCommand(AddCmd(cfg))
// Remote operations
root.AddCommand(CheckoutCmd(cfg))
root.AddCommand(PushCmd(cfg))
root.AddCommand(SubmitCmd(cfg))
root.AddCommand(SyncCmd(cfg))
root.AddCommand(UnstackCmd(cfg))
root.AddCommand(MergeCmd(cfg))
// Helper commands
root.AddCommand(ViewCmd(cfg))
root.AddCommand(RebaseCmd(cfg))
// Navigation commands
root.AddCommand(UpCmd(cfg))
root.AddCommand(DownCmd(cfg))
root.AddCommand(TopCmd(cfg))
root.AddCommand(BottomCmd(cfg))
// Alias
root.AddCommand(AliasCmd(cfg))
// Feedback
root.AddCommand(FeedbackCmd(cfg))
return root
}
func Execute() {
cmd := RootCmd()
// Wrap in a "gh" parent so help output shows "gh stack" instead of just "stack".
wrapCmd := &cobra.Command{Use: "gh", SilenceUsage: true, SilenceErrors: true}
wrapCmd.AddCommand(cmd)
wrapCmd.SetArgs(append([]string{"stack"}, os.Args[1:]...))
if err := wrapCmd.Execute(); err != nil {
var exitErr *ExitError
if errors.As(err, &exitErr) {
os.Exit(exitErr.Code)
}
fmt.Fprintln(cmd.ErrOrStderr(), err)
os.Exit(1)
}
}