Skip to content

Commit e69c7b1

Browse files
authored
Merge pull request #414 from Sixeight/sixeight/improve-silent-flag
improve --silent flag in get command
2 parents ea5ed54 + 2d66830 commit e69c7b1

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

cmd_get.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bufio"
55
"errors"
66
"fmt"
7+
"io"
78
"os"
89
"os/exec"
910
"path/filepath"
@@ -23,13 +24,14 @@ func doGet(c *cli.Context) error {
2324
args = c.Args().Slice()
2425
andLook = c.Bool("look")
2526
parallel = c.Bool("parallel")
27+
silent = c.Bool("silent")
2628
)
2729
g := &getter{
2830
update: c.Bool("update"),
2931
shallow: c.Bool("shallow"),
3032
ssh: c.Bool("p"),
3133
vcs: c.String("vcs"),
32-
silent: c.Bool("silent"),
34+
silent: silent,
3335
branch: c.String("branch"),
3436
recursive: !c.Bool("no-recursive"),
3537
bare: c.Bool("bare"),
@@ -38,6 +40,9 @@ func doGet(c *cli.Context) error {
3840
// force silent in parallel import
3941
g.silent = true
4042
}
43+
if silent {
44+
logger.SetOutput(io.Discard)
45+
}
4146

4247
var (
4348
firstArg string // Look at the first repo only, if there are more than one

cmd_get_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,33 @@ func TestCommandGet(t *testing.T) {
221221
t.Errorf("cloneArgs.bare should be true")
222222
}
223223
},
224+
}, {
225+
name: "silent mode",
226+
scenario: func(t *testing.T, tmpRoot string, cloneArgs *_cloneArgs, updateArgs *_updateArgs) {
227+
localDir := filepath.Join(tmpRoot, "github.com", "motemen", "ghq-test-repo")
228+
229+
out, _, err := captureWithInput([]string{}, func() {
230+
app.Run([]string{"", "get", "--silent", "motemen/ghq-test-repo"})
231+
})
232+
if err != nil {
233+
t.Errorf("error should be nil, but: %s", err)
234+
}
235+
236+
expect := "https://github.com/motemen/ghq-test-repo"
237+
if cloneArgs.remote.String() != expect {
238+
t.Errorf("got: %s, expect: %s", cloneArgs.remote, expect)
239+
}
240+
if filepath.ToSlash(cloneArgs.local) != filepath.ToSlash(localDir) {
241+
t.Errorf("got: %s, expect: %s", filepath.ToSlash(cloneArgs.local), filepath.ToSlash(localDir))
242+
}
243+
244+
if !cloneArgs.silent {
245+
t.Errorf("cloneArgs.silent should be true")
246+
}
247+
if out != "" {
248+
t.Errorf("silent mode should not output any logs, but got: %s", out)
249+
}
250+
},
224251
}}
225252

226253
for _, tc := range testCases {

commands_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ type _cloneArgs struct {
1414
branch string
1515
recursive bool
1616
bare bool
17+
silent bool
1718
}
1819

1920
type _updateArgs struct {
@@ -39,6 +40,7 @@ func withFakeGitBackend(t *testing.T, block func(*testing.T, string, *_cloneArgs
3940
branch: vg.branch,
4041
recursive: vg.recursive,
4142
bare: vg.bare,
43+
silent: vg.silent,
4244
}
4345
return nil
4446
},

0 commit comments

Comments
 (0)