Skip to content

Commit de5a937

Browse files
committed
basic terminal setup
1 parent c6da4fc commit de5a937

6 files changed

Lines changed: 177 additions & 20 deletions

File tree

cmd/placeholder.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package cmd
2+
3+
import (
4+
"github.com/github/gh-stack/internal/config"
5+
"github.com/spf13/cobra"
6+
)
7+
8+
type placeholderDef struct {
9+
Name string
10+
Short string
11+
}
12+
13+
var placeholderCommands = []placeholderDef{
14+
{"remove", "Remove a branch from a stack"},
15+
{"modify", "Modify a branch in a stack"},
16+
{"reorder", "Reorder branches in a stack"},
17+
{"move", "Move a branch between stacks"},
18+
{"fold", "Fold a branch into the branch below it"},
19+
{"squash", "Squash commits in a branch"},
20+
{"rename", "Rename a branch in a stack"},
21+
{"split", "Split a branch into two branches"},
22+
}
23+
24+
func PlaceholderCmd(def placeholderDef, cfg *config.Config) *cobra.Command {
25+
return &cobra.Command{
26+
Use: def.Name,
27+
Short: def.Short,
28+
Hidden: true,
29+
RunE: func(cmd *cobra.Command, args []string) error {
30+
cfg.Warningf("`gh stack %s` is not yet supported.", def.Name)
31+
cfg.Infof("Run `gh stack feedback` to share your thoughts on this feature.")
32+
return nil
33+
},
34+
}
35+
}

cmd/root.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package cmd
2+
3+
import (
4+
"os"
5+
6+
"github.com/github/gh-stack/internal/config"
7+
"github.com/spf13/cobra"
8+
)
9+
10+
func RootCmd() *cobra.Command {
11+
cfg := config.New()
12+
13+
root := &cobra.Command{
14+
Use: "stack <command>",
15+
Short: "Manage stacked branches and pull requests",
16+
Long: "Create, navigate, and manage stacks of branches and pull requests.",
17+
SilenceUsage: true,
18+
SilenceErrors: true,
19+
}
20+
21+
root.SetOut(cfg.Out)
22+
root.SetErr(cfg.Err)
23+
24+
for _, ph := range placeholderCommands {
25+
root.AddCommand(PlaceholderCmd(ph, cfg))
26+
}
27+
28+
return root
29+
}
30+
31+
func Execute() {
32+
cmd := RootCmd()
33+
if err := cmd.Execute(); err != nil {
34+
os.Exit(1)
35+
}
36+
}

go.mod

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module github.com/githubnext/gh-stack
1+
module github.com/github/gh-stack
22

33
go 1.25.7
44

@@ -9,11 +9,16 @@ require (
99
github.com/cli/safeexec v1.0.0 // indirect
1010
github.com/cli/shurcooL-graphql v0.0.4 // indirect
1111
github.com/henvic/httpretty v0.0.6 // indirect
12+
github.com/inconshreveable/mousetrap v1.1.0 // indirect
1213
github.com/kr/pretty v0.3.1 // indirect
1314
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
15+
github.com/mattn/go-colorable v0.1.13 // indirect
1416
github.com/mattn/go-isatty v0.0.20 // indirect
17+
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect
1518
github.com/muesli/termenv v0.16.0 // indirect
1619
github.com/rivo/uniseg v0.4.7 // indirect
20+
github.com/spf13/cobra v1.10.2 // indirect
21+
github.com/spf13/pflag v1.0.9 // indirect
1722
github.com/thlib/go-timezone-local v0.0.0-20210907160436-ef149e42d28e // indirect
1823
golang.org/x/sys v0.31.0 // indirect
1924
golang.org/x/term v0.30.0 // indirect

go.sum

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,29 @@ github.com/cli/safeexec v1.0.0 h1:0VngyaIyqACHdcMNWfo6+KdUYnqEr2Sg+bSP1pdF+dI=
66
github.com/cli/safeexec v1.0.0/go.mod h1:Z/D4tTN8Vs5gXYHDCbaM1S/anmEDnJb1iW0+EJ5zx3Q=
77
github.com/cli/shurcooL-graphql v0.0.4 h1:6MogPnQJLjKkaXPyGqPRXOI2qCsQdqNfUY1QSJu2GuY=
88
github.com/cli/shurcooL-graphql v0.0.4/go.mod h1:3waN4u02FiZivIV+p1y4d0Jo1jc6BViMA73C+sZo2fk=
9+
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
910
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
1011
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
1112
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
1213
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 h1:2VTzZjLZBgl62/EtslCrtky5vbi9dd7HrQPQIx6wqiw=
1314
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542/go.mod h1:Ow0tF8D4Kplbc8s8sSb3V2oUCygFHVp8gC3Dn6U4MNI=
1415
github.com/henvic/httpretty v0.0.6 h1:JdzGzKZBajBfnvlMALXXMVQWxWMF/ofTy8C3/OSUTxs=
1516
github.com/henvic/httpretty v0.0.6/go.mod h1:X38wLjWXHkXT7r2+uK8LjCMne9rsuNaBLJ+5cU2/Pmo=
17+
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
18+
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
1619
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
1720
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
1821
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
1922
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
2023
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
2124
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
25+
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
26+
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
27+
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
2228
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
2329
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
30+
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d h1:5PJl274Y63IEHC+7izoQE9x6ikvDFZS2mDVS3drnohI=
31+
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
2432
github.com/muesli/termenv v0.16.0 h1:S5AlUN9dENB57rsbnkPyfdGuWIlkmzJjbFf0Tf5FWUc=
2533
github.com/muesli/termenv v0.16.0/go.mod h1:ZRfOIKPFDYQoDFF4Olj7/QJbW60Ol/kL1pU3VfY/Cnk=
2634
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
@@ -30,11 +38,18 @@ github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
3038
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
3139
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
3240
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
41+
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
42+
github.com/spf13/cobra v1.10.2 h1:DMTTonx5m65Ic0GOoRY2c16WCbHxOOw6xxezuLaBpcU=
43+
github.com/spf13/cobra v1.10.2/go.mod h1:7C1pvHqHw5A4vrJfjNwvOdzYu0Gml16OCs2GRiTUUS4=
44+
github.com/spf13/pflag v1.0.9 h1:9exaQaMOCwffKiiiYk6/BndUBv+iRViNW+4lEMi0PvY=
45+
github.com/spf13/pflag v1.0.9/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
3346
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
3447
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
3548
github.com/thlib/go-timezone-local v0.0.0-20210907160436-ef149e42d28e h1:BuzhfgfWQbX0dWzYzT1zsORLnHRv3bcRcsaUk0VmXA8=
3649
github.com/thlib/go-timezone-local v0.0.0-20210907160436-ef149e42d28e/go.mod h1:/Tnicc6m/lsJE0irFMA0LfIwTBo4QP7A8IfyIv4zZKI=
50+
go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
3751
golang.org/x/sys v0.0.0-20210831042530-f4d43177bf5e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
52+
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
3853
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
3954
golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik=
4055
golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=

internal/config/config.go

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
package config
2+
3+
import (
4+
"fmt"
5+
"io"
6+
"os"
7+
8+
"github.com/cli/go-gh/v2/pkg/term"
9+
"github.com/mgutz/ansi"
10+
)
11+
12+
// Config holds shared state for all commands
13+
type Config struct {
14+
Terminal term.Term
15+
Out io.Writer
16+
Err io.Writer
17+
In io.Reader
18+
19+
ColorSuccess func(string) string
20+
ColorError func(string) string
21+
ColorWarning func(string) string
22+
ColorBold func(string) string
23+
ColorCyan func(string) string
24+
ColorGray func(string) string
25+
}
26+
27+
// New creates a new Config with terminal-aware output and color support
28+
func New() *Config {
29+
terminal := term.FromEnv()
30+
cfg := &Config{
31+
Terminal: terminal,
32+
Out: terminal.Out(),
33+
Err: terminal.ErrOut(),
34+
In: os.Stdin,
35+
}
36+
37+
if terminal.IsColorEnabled() {
38+
cfg.ColorSuccess = ansi.ColorFunc("green")
39+
cfg.ColorError = ansi.ColorFunc("red")
40+
cfg.ColorWarning = ansi.ColorFunc("yellow")
41+
cfg.ColorBold = ansi.ColorFunc("default+b")
42+
cfg.ColorCyan = ansi.ColorFunc("cyan")
43+
cfg.ColorGray = ansi.ColorFunc("white+d")
44+
} else {
45+
noop := func(s string) string { return s }
46+
cfg.ColorSuccess = noop
47+
cfg.ColorError = noop
48+
cfg.ColorWarning = noop
49+
cfg.ColorBold = noop
50+
cfg.ColorCyan = noop
51+
cfg.ColorGray = noop
52+
}
53+
54+
return cfg
55+
}
56+
57+
func (c *Config) Successf(format string, args ...any) {
58+
fmt.Fprintf(c.Err, "%s %s\n", c.ColorSuccess("\u2713"), fmt.Sprintf(format, args...))
59+
}
60+
61+
func (c *Config) Errorf(format string, args ...any) {
62+
fmt.Fprintf(c.Err, "%s %s\n", c.ColorError("\u2717"), fmt.Sprintf(format, args...))
63+
}
64+
65+
func (c *Config) Warningf(format string, args ...any) {
66+
fmt.Fprintf(c.Err, "%s %s\n", c.ColorWarning("\u26a0"), fmt.Sprintf(format, args...))
67+
}
68+
69+
func (c *Config) Infof(format string, args ...any) {
70+
fmt.Fprintf(c.Err, "%s %s\n", c.ColorCyan("\u2139"), fmt.Sprintf(format, args...))
71+
}
72+
73+
func (c *Config) Printf(format string, args ...any) {
74+
fmt.Fprintf(c.Err, format+"\n", args...)
75+
}
76+
77+
func (c *Config) Outf(format string, args ...any) {
78+
fmt.Fprintf(c.Out, format, args...)
79+
}
80+
81+
func (c *Config) IsInteractive() bool {
82+
return c.Terminal.IsTerminalOutput()
83+
}

main.go

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,9 @@
11
package main
22

33
import (
4-
"fmt"
5-
6-
"github.com/cli/go-gh/v2/pkg/api"
4+
"github.com/github/gh-stack/cmd"
75
)
86

97
func main() {
10-
fmt.Println("hi world, this is the gh-stack extension!")
11-
client, err := api.DefaultRESTClient()
12-
if err != nil {
13-
fmt.Println(err)
14-
return
15-
}
16-
response := struct {Login string}{}
17-
err = client.Get("user", &response)
18-
if err != nil {
19-
fmt.Println(err)
20-
return
21-
}
22-
fmt.Printf("running as %s\n", response.Login)
8+
cmd.Execute()
239
}
24-
25-
// For more examples of using go-gh, see:
26-
// https://github.com/cli/go-gh/blob/trunk/example_gh_test.go

0 commit comments

Comments
 (0)