Repository navigation
Expand file tree
/
Copy pathroot.go
More file actions
172 lines (136 loc) · 4.04 KB
/
Copy pathroot.go
File metadata and controls
172 lines (136 loc) · 4.04 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
package cmd
import (
"errors"
"fmt"
"os"
"github.com/github/gh-stack/internal/config"
"github.com/github/gh-stack/internal/theme"
"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: `Stacked PRs let you break a large change into a chain of pull requests
that build on each other. Use ` + "`gh stack`" + ` to create and manage your stack
locally, then push to GitHub to create your stack of PRs.`,
Example: ` # Start a new stack targeting your default branch
$ gh stack init
# Or turn an existing set of branches into a stack
$ gh stack init branch1 branch2 branch3
# Make changes and commit, then add a branch to the stack
$ gh stack add branch4
# Push all branches and create/update PRs on GitHub
$ gh stack submit
# Keep your local in sync with remote
$ gh stack sync`,
Version: Version,
SilenceUsage: true,
SilenceErrors: true,
// Honor GH_STACK_THEME (auto|light|dark) before any command renders
PersistentPreRun: func(_ *cobra.Command, _ []string) {
theme.ApplyOverride()
},
}
root.SetVersionTemplate("gh stack version {{.Version}}\n")
root.SetOut(cfg.Out)
root.SetErr(cfg.Err)
root.AddGroup(
&cobra.Group{ID: "stack", Title: "Stack management:"},
&cobra.Group{ID: "remote", Title: "Remote operations:"},
&cobra.Group{ID: "nav", Title: "Navigation:"},
&cobra.Group{ID: "utils", Title: "Utilities:"},
)
defaultHelp := root.HelpFunc()
root.SetHelpFunc(func(cmd *cobra.Command, args []string) {
defaultHelp(cmd, args)
if cmd.Name() == "stack" {
out := cmd.OutOrStderr()
fmt.Fprintln(out)
fmt.Fprintln(out, "Learn more:")
fmt.Fprintln(out, " Documentation: https://gh.io/stacks")
fmt.Fprintln(out, " Feedback: https://gh.io/stacks-feedback")
}
})
// Stack management commands
initCmd := InitCmd(cfg)
initCmd.GroupID = "stack"
root.AddCommand(initCmd)
addCmd := AddCmd(cfg)
addCmd.GroupID = "stack"
root.AddCommand(addCmd)
viewCmd := ViewCmd(cfg)
viewCmd.GroupID = "stack"
root.AddCommand(viewCmd)
checkoutCmd := CheckoutCmd(cfg)
checkoutCmd.GroupID = "stack"
root.AddCommand(checkoutCmd)
modifyCmd := ModifyCmd(cfg)
modifyCmd.GroupID = "stack"
root.AddCommand(modifyCmd)
unstackCmd := UnstackCmd(cfg)
unstackCmd.GroupID = "stack"
root.AddCommand(unstackCmd)
// Remote operations commands
submitCmd := SubmitCmd(cfg)
submitCmd.GroupID = "remote"
root.AddCommand(submitCmd)
syncCmd := SyncCmd(cfg)
syncCmd.GroupID = "remote"
root.AddCommand(syncCmd)
rebaseCmd := RebaseCmd(cfg)
rebaseCmd.GroupID = "remote"
root.AddCommand(rebaseCmd)
pushCmd := PushCmd(cfg)
pushCmd.GroupID = "remote"
root.AddCommand(pushCmd)
linkCmd := LinkCmd(cfg)
linkCmd.GroupID = "remote"
root.AddCommand(linkCmd)
mergeCmd := MergeCmd(cfg)
mergeCmd.GroupID = "remote"
root.AddCommand(mergeCmd)
// Navigation commands
switchCmd := SwitchCmd(cfg)
switchCmd.GroupID = "nav"
root.AddCommand(switchCmd)
upCmd := UpCmd(cfg)
upCmd.GroupID = "nav"
root.AddCommand(upCmd)
downCmd := DownCmd(cfg)
downCmd.GroupID = "nav"
root.AddCommand(downCmd)
topCmd := TopCmd(cfg)
topCmd.GroupID = "nav"
root.AddCommand(topCmd)
bottomCmd := BottomCmd(cfg)
bottomCmd.GroupID = "nav"
root.AddCommand(bottomCmd)
trunkCmd := TrunkCmd(cfg)
trunkCmd.GroupID = "nav"
root.AddCommand(trunkCmd)
// Utility commands
aliasCmd := AliasCmd(cfg)
aliasCmd.GroupID = "utils"
root.AddCommand(aliasCmd)
feedbackCmd := FeedbackCmd(cfg)
feedbackCmd.GroupID = "utils"
root.AddCommand(feedbackCmd)
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)
}
}