X Tutup
Skip to content

Commit e0fa56d

Browse files
committed
Merge remote-tracking branch 'origin' into go-module-v2
2 parents 11fbb60 + 1af6a66 commit e0fa56d

File tree

10 files changed

+82
-72
lines changed

10 files changed

+82
-72
lines changed

pkg/cmd/actions/actions.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,5 @@ func actionsExplainer(cs *iostreams.ColorScheme) string {
5656
gh workflow run: Trigger a workflow_dispatch run for a workflow file
5757
5858
To see more help, run 'gh help workflow <subcommand>'
59-
60-
For more in depth help including examples, see online documentation at:
61-
<https://docs.github.com/en/actions/guides/managing-github-actions-with-github-cli>
6259
`, header, runHeader, workflowHeader)
6360
}

pkg/cmd/browse/browse.go

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,28 @@ func parseFileArg(fileArg string) (string, error) {
169169
if len(arr) > 2 {
170170
return "", fmt.Errorf("invalid use of colon\nUse 'gh browse --help' for more information about browse\n")
171171
}
172+
172173
if len(arr) > 1 {
173-
if !isNumber(arr[1]) {
174-
return "", fmt.Errorf("invalid line number after colon\nUse 'gh browse --help' for more information about browse\n")
174+
out := arr[0] + "#L"
175+
lineRange := strings.Split(arr[1], "-")
176+
177+
if len(lineRange) > 0 {
178+
if !isNumber(lineRange[0]) {
179+
return "", fmt.Errorf("invalid line number after colon\nUse 'gh browse --help' for more information about browse\n")
180+
}
181+
out += lineRange[0]
182+
}
183+
184+
if len(lineRange) > 1 {
185+
if !isNumber(lineRange[1]) {
186+
return "", fmt.Errorf("invalid line range after colon\nUse 'gh browse --help' for more information about browse\n")
187+
}
188+
out += "-L" + lineRange[1]
175189
}
176-
return arr[0] + "#L" + arr[1], nil
190+
191+
return out, nil
177192
}
193+
178194
return arr[0], nil
179195
}
180196

pkg/cmd/browse/browse_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,15 @@ func Test_runBrowse(t *testing.T) {
215215
defaultBranch: "trunk",
216216
expectedURL: "https://github.com/ravocean/angur/tree/trunk/path/to/file.txt#L32",
217217
},
218+
{
219+
name: "file with line range",
220+
opts: BrowseOptions{
221+
SelectorArg: "path/to/file.txt:32-40",
222+
},
223+
baseRepo: ghrepo.New("ravocean", "angur"),
224+
defaultBranch: "trunk",
225+
expectedURL: "https://github.com/ravocean/angur/tree/trunk/path/to/file.txt#L32-L40",
226+
},
218227
{
219228
name: "file with invalid line number",
220229
opts: BrowseOptions{
@@ -223,6 +232,14 @@ func Test_runBrowse(t *testing.T) {
223232
baseRepo: ghrepo.New("ttran112", "ttrain211"),
224233
wantsErr: true,
225234
},
235+
{
236+
name: "file with invalid line range",
237+
opts: BrowseOptions{
238+
SelectorArg: "path/to/file.txt:32-abc",
239+
},
240+
baseRepo: ghrepo.New("ttran112", "ttrain211"),
241+
wantsErr: true,
242+
},
226243
{
227244
name: "branch with issue number",
228245
opts: BrowseOptions{

pkg/cmd/extension/manager.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ func (m *Manager) Create(name string) error {
268268
}
269269

270270
fileTmpl := heredoc.Docf(`
271-
#!/bin/bash
271+
#!/usr/bin/env bash
272272
set -e
273273
274274
echo "Hello %[1]s!"

pkg/cmd/issue/create/create.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func NewCmdCreate(f *cmdutil.Factory, runF func(*CreateOptions) error) *cobra.Co
6262
$ gh issue create --label "bug,help wanted"
6363
$ gh issue create --label bug --label "help wanted"
6464
$ gh issue create --assignee monalisa,hubot
65-
$ gh issue create --assignee @me
65+
$ gh issue create --assignee "@me"
6666
$ gh issue create --project "Roadmap"
6767
`),
6868
Args: cmdutil.NoArgsQuoteReminder,

pkg/cmd/issue/edit/edit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func NewCmdEdit(f *cmdutil.Factory, runF func(*EditOptions) error) *cobra.Comman
5050
Example: heredoc.Doc(`
5151
$ gh issue edit 23 --title "I found a bug" --body "Nothing works"
5252
$ gh issue edit 23 --add-label "bug,help wanted" --remove-label "core"
53-
$ gh issue edit 23 --add-assignee @me --remove-assignee monalisa,hubot
53+
$ gh issue edit 23 --add-assignee "@me" --remove-assignee monalisa,hubot
5454
$ gh issue edit 23 --add-project "Roadmap" --remove-project v1,v2
5555
$ gh issue edit 23 --milestone "Version 1"
5656
$ gh issue edit 23 --body-file body.txt

pkg/cmd/issue/list/list.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func NewCmdList(f *cmdutil.Factory, runF func(*ListOptions) error) *cobra.Comman
5757
Example: heredoc.Doc(`
5858
$ gh issue list -l "bug" -l "help wanted"
5959
$ gh issue list -A monalisa
60-
$ gh issue list -a @me
60+
$ gh issue list -a "@me"
6161
$ gh issue list --web
6262
$ gh issue list --milestone "The big 1.0"
6363
$ gh issue list --search "error no:assignee sort:created-asc"

pkg/cmd/pr/edit/edit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func NewCmdEdit(f *cmdutil.Factory, runF func(*EditOptions) error) *cobra.Comman
5555
$ gh pr edit 23 --title "I found a bug" --body "Nothing works"
5656
$ gh pr edit 23 --add-label "bug,help wanted" --remove-label "core"
5757
$ gh pr edit 23 --add-reviewer monalisa,hubot --remove-reviewer myorg/team-name
58-
$ gh pr edit 23 --add-assignee @me --remove-assignee monalisa,hubot
58+
$ gh pr edit 23 --add-assignee "@me" --remove-assignee monalisa,hubot
5959
$ gh pr edit 23 --add-project "Roadmap" --remove-project v1,v2
6060
$ gh pr edit 23 --milestone "Version 1"
6161
`),

pkg/cmd/pr/list/list.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ func NewCmdList(f *cmdutil.Factory, runF func(*ListOptions) error) *cobra.Comman
5151
Short: "List and filter pull requests in this repository",
5252
Example: heredoc.Doc(`
5353
List PRs authored by you
54-
$ gh pr list --author @me
54+
$ gh pr list --author "@me"
5555
5656
List PRs assigned to you
57-
$ gh pr list --assignee @me
57+
$ gh pr list --assignee "@me"
5858
5959
List PRs by label, combining multiple labels with AND
6060
$ gh pr list --label bug --label "priority 1"

pkg/cmd/repo/garden/garden.go

Lines changed: 39 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@ import (
88
"net/http"
99
"os"
1010
"os/exec"
11-
"os/signal"
1211
"runtime"
1312
"strconv"
1413
"strings"
15-
"syscall"
1614

1715
"github.com/cli/cli/v2/api"
1816
"github.com/cli/cli/v2/internal/ghinstance"
@@ -21,6 +19,7 @@ import (
2119
"github.com/cli/cli/v2/pkg/iostreams"
2220
"github.com/cli/cli/v2/utils"
2321
"github.com/spf13/cobra"
22+
"golang.org/x/term"
2423
)
2524

2625
type Geometry struct {
@@ -51,10 +50,11 @@ type Cell struct {
5150
}
5251

5352
const (
54-
DirUp = iota
53+
DirUp Direction = iota
5554
DirDown
5655
DirLeft
5756
DirRight
57+
Quit
5858
)
5959

6060
type Direction = int
@@ -182,18 +182,6 @@ func gardenRun(opts *GardenOptions) error {
182182

183183
maxCommits := (geo.Width * geo.Height) / 2
184184

185-
sttyFileArg := "-F"
186-
if runtime.GOOS == "darwin" {
187-
sttyFileArg = "-f"
188-
}
189-
190-
oldTTYCommand := exec.Command("stty", sttyFileArg, "/dev/tty", "-g")
191-
oldTTYSettings, err := oldTTYCommand.CombinedOutput()
192-
if err != nil {
193-
fmt.Fprintln(out, "getting TTY settings failed:", string(oldTTYSettings))
194-
return err
195-
}
196-
197185
opts.IO.StartProgressIndicator()
198186
fmt.Fprintln(out, "gathering commits; this could take a minute...")
199187
commits, err := getCommits(httpClient, toView, maxCommits)
@@ -215,57 +203,42 @@ func gardenRun(opts *GardenOptions) error {
215203
clear(opts.IO)
216204
drawGarden(opts.IO, garden, player)
217205

218-
// thanks stackoverflow https://stackoverflow.com/a/17278776
219-
_ = exec.Command("stty", sttyFileArg, "/dev/tty", "cbreak", "min", "1").Run()
220-
_ = exec.Command("stty", sttyFileArg, "/dev/tty", "-echo").Run()
221-
222-
walkAway := func() {
223-
clear(opts.IO)
224-
fmt.Fprint(out, "\033[?25h")
225-
_ = exec.Command("stty", sttyFileArg, "/dev/tty", strings.TrimSpace(string(oldTTYSettings))).Run()
226-
fmt.Fprintln(out)
227-
fmt.Fprintln(out, cs.Bold("You turn and walk away from the wildflower garden..."))
206+
// TODO: use opts.IO instead of os.Stdout
207+
oldTermState, err := term.MakeRaw(int(os.Stdout.Fd()))
208+
if err != nil {
209+
return fmt.Errorf("term.MakeRaw: %w", err)
228210
}
229211

230-
c := make(chan os.Signal)
231-
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
212+
dirc := make(chan Direction)
232213
go func() {
233-
<-c
234-
walkAway()
235-
os.Exit(0)
214+
b := make([]byte, 3)
215+
for {
216+
_, _ = opts.IO.In.Read(b)
217+
switch {
218+
case isLeft(b):
219+
dirc <- DirLeft
220+
case isRight(b):
221+
dirc <- DirRight
222+
case isUp(b):
223+
dirc <- DirUp
224+
case isDown(b):
225+
dirc <- DirDown
226+
case isQuit(b):
227+
dirc <- Quit
228+
}
229+
}
236230
}()
237231

238-
var b []byte = make([]byte, 3)
232+
mainLoop:
239233
for {
240-
_, _ = opts.IO.In.Read(b)
241-
242234
oldX := player.X
243235
oldY := player.Y
244-
moved := false
245-
quitting := false
246-
continuing := false
247-
248-
switch {
249-
case isLeft(b):
250-
moved = player.move(DirLeft)
251-
case isRight(b):
252-
moved = player.move(DirRight)
253-
case isUp(b):
254-
moved = player.move(DirUp)
255-
case isDown(b):
256-
moved = player.move(DirDown)
257-
case isQuit(b):
258-
quitting = true
259-
default:
260-
continuing = true
261-
}
262236

263-
if quitting {
264-
break
265-
}
266-
267-
if !moved || continuing {
268-
continue
237+
d := <-dirc
238+
if d == Quit {
239+
break mainLoop
240+
} else if !player.move(d) {
241+
continue mainLoop
269242
}
270243

271244
underPlayer := garden[player.Y][player.X]
@@ -315,7 +288,12 @@ func gardenRun(opts *GardenOptions) error {
315288
fmt.Fprint(out, cs.Bold(sl))
316289
}
317290

318-
walkAway()
291+
clear(opts.IO)
292+
fmt.Fprint(out, "\033[?25h")
293+
// TODO: use opts.IO instead of os.Stdout
294+
_ = term.Restore(int(os.Stdout.Fd()), oldTermState)
295+
fmt.Fprintln(out, cs.Bold("You turn and walk away from the wildflower garden..."))
296+
319297
return nil
320298
}
321299

@@ -343,8 +321,10 @@ func isUp(b []byte) bool {
343321
return bytes.EqualFold(b, up) || r == 'w' || r == 'k'
344322
}
345323

324+
var ctrlC = []byte{0x3, 0x5b, 0x43}
325+
346326
func isQuit(b []byte) bool {
347-
return rune(b[0]) == 'q'
327+
return rune(b[0]) == 'q' || bytes.Equal(b, ctrlC)
348328
}
349329

350330
func plantGarden(commits []*Commit, geo *Geometry) [][]*Cell {

0 commit comments

Comments
 (0)
X Tutup