Skip to content

Commit 7489a77

Browse files
authored
Merge pull request #2841 from alexandear/refactor/forbid-fmt-print
refactor: replace fmt.Print with an explicit out to Stdout
2 parents 19a3d68 + ad57ef9 commit 7489a77

File tree

5 files changed

+10
-8
lines changed

5 files changed

+10
-8
lines changed

.golangci.yml

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ linters:
4141
# - exhaustivestruct
4242
# - exportloopref
4343
# - funlen
44+
- forbidigo
4445
# - gci
4546
# - gochecknoglobals
4647
# - gochecknoinits

cmd/limactl/list.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ func listAction(cmd *cobra.Command, args []string) error {
123123
if listFields {
124124
names := fieldNames()
125125
sort.Strings(names)
126-
fmt.Println(strings.Join(names, "\n"))
126+
fmt.Fprintln(cmd.OutOrStdout(), strings.Join(names, "\n"))
127127
return nil
128128
}
129129

cmd/limactl/snapshot.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,11 @@ func snapshotListAction(cmd *cobra.Command, args []string) error {
177177
continue
178178
}
179179
tag := fields[1]
180-
fmt.Printf("%s\n", tag)
180+
fmt.Fprintf(cmd.OutOrStdout(), "%s\n", tag)
181181
}
182182
return nil
183183
}
184-
fmt.Print(out)
184+
fmt.Fprint(cmd.OutOrStdout(), out)
185185
return nil
186186
}
187187

cmd/limactl/sudoers.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package main
33
import (
44
"errors"
55
"fmt"
6+
"io"
67
"runtime"
78

89
"github.com/lima-vm/lima/pkg/networks"
@@ -55,7 +56,7 @@ func sudoersAction(cmd *cobra.Command, args []string) error {
5556
return err
5657
}
5758
if check {
58-
return verifySudoAccess(nwCfg, args)
59+
return verifySudoAccess(nwCfg, args, cmd.OutOrStdout())
5960
}
6061
switch len(args) {
6162
case 0:
@@ -69,11 +70,11 @@ func sudoersAction(cmd *cobra.Command, args []string) error {
6970
if err != nil {
7071
return err
7172
}
72-
fmt.Print(sudoers)
73+
fmt.Fprint(cmd.OutOrStdout(), sudoers)
7374
return nil
7475
}
7576

76-
func verifySudoAccess(nwCfg networks.Config, args []string) error {
77+
func verifySudoAccess(nwCfg networks.Config, args []string, stdout io.Writer) error {
7778
var file string
7879
switch len(args) {
7980
case 0:
@@ -90,6 +91,6 @@ func verifySudoAccess(nwCfg networks.Config, args []string) error {
9091
if err := nwCfg.VerifySudoAccess(file); err != nil {
9192
return err
9293
}
93-
fmt.Printf("%q is up-to-date (or sudo doesn't require a password)\n", file)
94+
fmt.Fprintf(stdout, "%q is up-to-date (or sudo doesn't require a password)\n", file)
9495
return nil
9596
}

pkg/instance/start.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ func ShowMessage(inst *store.Instance) error {
380380
logrus.Infof("Message from the instance %q:", inst.Name)
381381
for scanner.Scan() {
382382
// Avoid prepending logrus "INFO" header, for ease of copy pasting
383-
fmt.Println(scanner.Text())
383+
fmt.Fprintln(logrus.StandardLogger().Out, scanner.Text())
384384
}
385385
return scanner.Err()
386386
}

0 commit comments

Comments
 (0)