Skip to content

Commit

Permalink
chore(refactor): remove boolean flag
Browse files Browse the repository at this point in the history
Rather than pass a boolean to result.publish(), I now switch on that
same boolean to call two different methods, publish() or publishError().

On the one hand, this feels very picky. On the other hand, why not?
  • Loading branch information
telemachus committed Dec 16, 2024
1 parent 97c4475 commit 52e1406
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
7 changes: 6 additions & 1 deletion internal/cli/clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ func (app *appEnv) clone(rs []Repo) {
}
for range rs {
res := <-ch
res.publish(app.quiet)
switch app.quiet {
case true:
res.publishError()
default:
res.publish()
}
}
}

Expand Down
11 changes: 6 additions & 5 deletions internal/cli/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@ type result struct {
isErr bool
}

func (r result) publish(quiet bool) {
func (r result) publish() {
if r.isErr {
fmt.Fprintln(os.Stderr, r.msg)
return
}
fmt.Fprintln(os.Stdout, r.msg)
}

if quiet {
return
func (r result) publishError() {
if r.isErr {
fmt.Fprintln(os.Stderr, r.msg)
}

fmt.Fprintln(os.Stdout, r.msg)
}
7 changes: 6 additions & 1 deletion internal/cli/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ func (app *appEnv) update(rs []Repo) {
}
for range rs {
res := <-ch
res.publish(app.quiet)
switch app.quiet {
case true:
res.publishError()
default:
res.publish()
}
}
}

Expand Down

0 comments on commit 52e1406

Please sign in to comment.