mirror of
https://github.com/lima-vm/lima.git
synced 2026-10-28 11:44:35 +08:00
refactor: replace fmt.Print with an explicit out to Stdout
Signed-off-by: Oleksandr Redko <oleksandr.red+github@gmail.com>
This commit is contained in:
5 files changed
+10
-8
No files matched your search
@@ -41,6 +41,7 @@ linters:
|
||||
# - exhaustivestruct
|
||||
# - exportloopref
|
||||
# - funlen
|
||||
- forbidigo
|
||||
# - gci
|
||||
# - gochecknoglobals
|
||||
# - gochecknoinits
|
||||
|
||||
+1
-1
@@ -123,7 +123,7 @@ func listAction(cmd *cobra.Command, args []string) error {
|
||||
if listFields {
|
||||
names := fieldNames()
|
||||
sort.Strings(names)
|
||||
fmt.Println(strings.Join(names, "\n"))
|
||||
fmt.Fprintln(cmd.OutOrStdout(), strings.Join(names, "\n"))
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -177,11 +177,11 @@ func snapshotListAction(cmd *cobra.Command, args []string) error {
|
||||
continue
|
||||
}
|
||||
tag := fields[1]
|
||||
fmt.Printf("%s\n", tag)
|
||||
fmt.Fprintf(cmd.OutOrStdout(), "%s\n", tag)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
fmt.Print(out)
|
||||
fmt.Fprint(cmd.OutOrStdout(), out)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"runtime"
|
||||
|
||||
"github.com/lima-vm/lima/pkg/networks"
|
||||
@@ -55,7 +56,7 @@ func sudoersAction(cmd *cobra.Command, args []string) error {
|
||||
return err
|
||||
}
|
||||
if check {
|
||||
return verifySudoAccess(nwCfg, args)
|
||||
return verifySudoAccess(nwCfg, args, cmd.OutOrStdout())
|
||||
}
|
||||
switch len(args) {
|
||||
case 0:
|
||||
@@ -69,11 +70,11 @@ func sudoersAction(cmd *cobra.Command, args []string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Print(sudoers)
|
||||
fmt.Fprint(cmd.OutOrStdout(), sudoers)
|
||||
return nil
|
||||
}
|
||||
|
||||
func verifySudoAccess(nwCfg networks.Config, args []string) error {
|
||||
func verifySudoAccess(nwCfg networks.Config, args []string, stdout io.Writer) error {
|
||||
var file string
|
||||
switch len(args) {
|
||||
case 0:
|
||||
@@ -90,6 +91,6 @@ func verifySudoAccess(nwCfg networks.Config, args []string) error {
|
||||
if err := nwCfg.VerifySudoAccess(file); err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Printf("%q is up-to-date (or sudo doesn't require a password)\n", file)
|
||||
fmt.Fprintf(stdout, "%q is up-to-date (or sudo doesn't require a password)\n", file)
|
||||
return nil
|
||||
}
|
||||
@@ -380,7 +380,7 @@ func ShowMessage(inst *store.Instance) error {
|
||||
logrus.Infof("Message from the instance %q:", inst.Name)
|
||||
for scanner.Scan() {
|
||||
// Avoid prepending logrus "INFO" header, for ease of copy pasting
|
||||
fmt.Println(scanner.Text())
|
||||
fmt.Fprintln(logrus.StandardLogger().Out, scanner.Text())
|
||||
}
|
||||
return scanner.Err()
|
||||
}
|
||||
Reference in new issue
Block a user