Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lint fixes (inamedparam) #135

Merged
merged 1 commit into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions cmd/rigtest/rigtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ import (
)

type TestingT interface {
Errorf(format string, args ...interface{})
Errorf(format string, args ...any)
FailNow()
}

type testRunner struct{}

func (t testRunner) Run(name string, args ...interface{}) {
func (t testRunner) Run(name string, args ...any) {
fmt.Println("* Running test:", fmt.Sprintf(name, args...))
}

func (t testRunner) Errorf(format string, args ...interface{}) {
func (t testRunner) Errorf(format string, args ...any) {
println(fmt.Sprintf(format, args...))
}

Expand Down
9 changes: 5 additions & 4 deletions connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package rig

import (
"crypto/sha256"
"encoding/hex"
"fmt"
"io"
"os"
Expand All @@ -28,9 +29,9 @@ type client interface {
Connect() error
Disconnect()
IsWindows() bool
Exec(string, ...exec.Option) error
ExecStreams(string, io.ReadCloser, io.Writer, io.Writer, ...exec.Option) (waiter, error)
ExecInteractive(string) error
Exec(cmd string, opts ...exec.Option) error
ExecStreams(cmd string, stdin io.ReadCloser, stdout io.Writer, stderr io.Writer, opts ...exec.Option) (waiter, error)
ExecInteractive(cmd string) error
String() string
Protocol() string
IPAddress() string
Expand Down Expand Up @@ -387,7 +388,7 @@ func (c *Connection) Upload(src, dst string, _ ...exec.Option) error {
return fmt.Errorf("%w: validate %s checksum: %w", ErrUploadFailed, dst, err)
}

if remoteSum != fmt.Sprintf("%x", shasum.Sum(nil)) {
if remoteSum != hex.EncodeToString(shasum.Sum(nil)) {
return fmt.Errorf("%w: checksum mismatch", ErrUploadFailed)
}

Expand Down
8 changes: 6 additions & 2 deletions examples/os/stock/stock.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
)

type configurer interface {
Pwd(os.Host) string
Pwd(host os.Host) string
}

// Host is a host that utilizes rig for connections
Expand All @@ -39,7 +39,11 @@ func (h *Host) LoadOS() error {
return err
}

h.Configurer = bf().(configurer)
c, ok := bf().(configurer)
if !ok {
return fmt.Errorf("OS %s does not support configurer interface", *h.OSVersion)
}
h.Configurer = c

return nil
}
Expand Down
10 changes: 7 additions & 3 deletions examples/upload/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (
)

type configurer interface {
Pwd(os.Host) string
CheckPrivilege(os.Host) error
Pwd(host os.Host) string
CheckPrivilege(host os.Host) error
}

// Host is a host that utilizes rig for connections
Expand All @@ -33,7 +33,11 @@ func (h *Host) LoadOS() error {
return err
}

h.Configurer = bf().(configurer)
c, ok := bf().(configurer)
if !ok {
return fmt.Errorf("OS %s does not support configurer interface", *h.OSVersion)
}
h.Configurer = c

return nil
}
Expand Down
14 changes: 7 additions & 7 deletions exec/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ var (
Confirm = false

// DebugFunc can be replaced to direct the output of exec logging into your own function (standard sprintf interface)
DebugFunc = func(s string, args ...interface{}) {
DebugFunc = func(s string, args ...any) {
log.Debugf(s, args...)
}

// InfoFunc can be replaced to direct the output of exec logging into your own function (standard sprintf interface)
InfoFunc = func(s string, args ...interface{}) {
InfoFunc = func(s string, args ...any) {
log.Infof(s, args...)
}

// ErrorFunc can be replaced to direct the output of exec logging into your own function (standard sprintf interface)
ErrorFunc = func(s string, args ...interface{}) {
ErrorFunc = func(s string, args ...any) {
log.Errorf(s, args...)
}

Expand Down Expand Up @@ -69,7 +69,7 @@ type Options struct {
}

type host interface {
Sudo(string) (string, error)
Sudo(cmd string) (string, error)
}

// Command returns the command wrapped in a sudo if sudo is enabled or the original command
Expand Down Expand Up @@ -117,21 +117,21 @@ func (o *Options) LogStdin(prefix string) {
}

// LogDebugf is a conditional debug logger
func (o *Options) LogDebugf(s string, args ...interface{}) {
func (o *Options) LogDebugf(s string, args ...any) {
if o.LogDebug {
DebugFunc(s, args...)
}
}

// LogInfof is a conditional info logger
func (o *Options) LogInfof(s string, args ...interface{}) {
func (o *Options) LogInfof(s string, args ...any) {
if o.LogInfo {
InfoFunc(s, args...)
}
}

// LogErrorf is a conditional error logger
func (o *Options) LogErrorf(s string, args ...interface{}) {
func (o *Options) LogErrorf(s string, args ...any) {
if o.LogError {
ErrorFunc(s, args...)
}
Expand Down
30 changes: 15 additions & 15 deletions log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,38 @@ import "fmt"

// Logger interface should be implemented by the logging library you wish to use
type Logger interface {
Tracef(string, ...interface{})
Debugf(string, ...interface{})
Infof(string, ...interface{})
Warnf(string, ...interface{})
Errorf(string, ...interface{})
Tracef(msg string, args ...any)
Debugf(msg string, args ...any)
Infof(msg string, args ...any)
Warnf(msg string, args ...any)
Errorf(msg string, args ...any)
}

// Log can be assigned a proper logger, such as logrus configured to your liking.
var Log Logger

// Tracef logs a trace level log message
func Tracef(t string, args ...interface{}) {
func Tracef(t string, args ...any) {
Log.Tracef(t, args...)
}

// Debugf logs a debug level log message
func Debugf(t string, args ...interface{}) {
func Debugf(t string, args ...any) {
Log.Debugf(t, args...)
}

// Infof logs an info level log message
func Infof(t string, args ...interface{}) {
func Infof(t string, args ...any) {
Log.Infof(t, args...)
}

// Errorf logs an error level log message
func Errorf(t string, args ...interface{}) {
func Errorf(t string, args ...any) {
Log.Errorf(t, args...)
}

// Warnf logs a warn level log message
func Warnf(t string, args ...interface{}) {
func Warnf(t string, args ...any) {
Log.Warnf(t, args...)
}

Expand All @@ -46,26 +46,26 @@ type StdLog struct {
}

// Tracef prints a debug level log message
func (l *StdLog) Tracef(t string, args ...interface{}) {
func (l *StdLog) Tracef(t string, args ...any) {
fmt.Println("TRACE", fmt.Sprintf(t, args...))
}

// Debugf prints a debug level log message
func (l *StdLog) Debugf(t string, args ...interface{}) {
func (l *StdLog) Debugf(t string, args ...any) {
fmt.Println("DEBUG", fmt.Sprintf(t, args...))
}

// Infof prints an info level log message
func (l *StdLog) Infof(t string, args ...interface{}) {
func (l *StdLog) Infof(t string, args ...any) {
fmt.Println("INFO ", fmt.Sprintf(t, args...))
}

// Warnf prints a warn level log message
func (l *StdLog) Warnf(t string, args ...interface{}) {
func (l *StdLog) Warnf(t string, args ...any) {
fmt.Println("WARN", fmt.Sprintf(t, args...))
}

// Errorf prints an error level log message
func (l *StdLog) Errorf(t string, args ...interface{}) {
func (l *StdLog) Errorf(t string, args ...any) {
fmt.Println("ERROR", fmt.Sprintf(t, args...))
}
10 changes: 5 additions & 5 deletions os/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import (
// Host is an interface to a host object that has the functions needed by the various OS support packages
type Host interface {
Upload(source, destination string, opts ...exec.Option) error
Exec(string, ...exec.Option) error
ExecOutput(string, ...exec.Option) (string, error)
Execf(string, ...interface{}) error
ExecOutputf(string, ...interface{}) (string, error)
Exec(cmd string, opts ...exec.Option) error
ExecOutput(cmd string, opts ...exec.Option) (string, error)
Execf(cmd string, argsOrOpts ...any) error
ExecOutputf(cmd string, argsOrOpts ...any) (string, error)
String() string
Sudo(string) (string, error)
Sudo(cmd string) (string, error)
}
6 changes: 3 additions & 3 deletions os/initsystem/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package initsystem

// Host interface for init system
type Host interface {
Execf(string, ...interface{}) error
ExecOutputf(string, ...interface{}) (string, error)
Sudo(string) (string, error)
Execf(cmd string, args ...any) error
ExecOutputf(cmd string, args ...any) (string, error)
Sudo(cmd string) (string, error)
}
20 changes: 10 additions & 10 deletions os/linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ type Linux struct{}

// initSystem interface defines an init system - the OS's system to manage services (systemd, openrc for example)
type initSystem interface {
StartService(initsystem.Host, string) error
StopService(initsystem.Host, string) error
RestartService(initsystem.Host, string) error
DisableService(initsystem.Host, string) error
EnableService(initsystem.Host, string) error
ServiceIsRunning(initsystem.Host, string) bool
ServiceScriptPath(initsystem.Host, string) (string, error)
DaemonReload(initsystem.Host) error
ServiceEnvironmentPath(initsystem.Host, string) (string, error)
ServiceEnvironmentContent(map[string]string) string
StartService(host initsystem.Host, service string) error
StopService(host initsystem.Host, service string) error
RestartService(host initsystem.Host, service string) error
DisableService(host initsystem.Host, service string) error
EnableService(host initsystem.Host, service string) error
ServiceIsRunning(host initsystem.Host, service string) bool
ServiceScriptPath(host initsystem.Host, service string) (string, error)
DaemonReload(host initsystem.Host) error
ServiceEnvironmentPath(host initsystem.Host, srvice string) (string, error)
ServiceEnvironmentContent(envs map[string]string) string
}

// ErrInitSystemNotSupported is returned when the init system is not supported
Expand Down
2 changes: 1 addition & 1 deletion os/linux/alpine.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func init() {
func(os rig.OSVersion) bool {
return os.ID == "alpine"
},
func() interface{} {
func() any {
return &Alpine{}
},
)
Expand Down
2 changes: 1 addition & 1 deletion os/linux/archlinux.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func init() {
func(os rig.OSVersion) bool {
return os.IDLike == "arch"
},
func() interface{} {
func() any {
return Archlinux{}
},
)
Expand Down
2 changes: 1 addition & 1 deletion os/linux/debian.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func init() {
func(os rig.OSVersion) bool {
return os.ID == "debian"
},
func() interface{} {
func() any {
return Debian{}
},
)
Expand Down
2 changes: 1 addition & 1 deletion os/linux/enterpriselinux/centos.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func init() {
func(os rig.OSVersion) bool {
return os.ID == "centos"
},
func() interface{} {
func() any {
return CentOS{}
},
)
Expand Down
2 changes: 1 addition & 1 deletion os/linux/enterpriselinux/oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func init() {
func(os rig.OSVersion) bool {
return os.ID == "ol"
},
func() interface{} {
func() any {
return OracleLinux{}
},
)
Expand Down
2 changes: 1 addition & 1 deletion os/linux/enterpriselinux/rhel.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func init() {
func(os rig.OSVersion) bool {
return os.ID == "rhel"
},
func() interface{} {
func() any {
return RHEL{}
},
)
Expand Down
2 changes: 1 addition & 1 deletion os/linux/sles.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func init() {
func(os rig.OSVersion) bool {
return os.ID == "sles"
},
func() interface{} {
func() any {
return SLES{}
},
)
Expand Down
2 changes: 1 addition & 1 deletion os/linux/ubuntu.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func init() {
func(os rig.OSVersion) bool {
return os.ID == "ubuntu"
},
func() interface{} {
func() any {
return Ubuntu{}
},
)
Expand Down
2 changes: 1 addition & 1 deletion os/mac/darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func init() {
func(os rig.OSVersion) bool {
return os.ID == "darwin"
},
func() interface{} {
func() any {
return Darwin{}
},
)
Expand Down
2 changes: 1 addition & 1 deletion os/registry/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
var ErrOSModuleNotFound = errors.New("os support module not found")

type (
buildFunc = func() interface{}
buildFunc = func() any
matchFunc = func(rig.OSVersion) bool
)

Expand Down
2 changes: 1 addition & 1 deletion os/windows/windows2019.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func init() {
func(os rig.OSVersion) bool {
return os.ID == "windows" && strings.HasPrefix(os.Version, "10.0.")
},
func() interface{} {
func() any {
return Windows2019{}
},
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/rigfs/posixfsys.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ func (f *PosixFile) CopyFromN(src io.Reader, num int64, alt io.Writer) (int64, e
}
var ddCmd string
if f.pos+num >= f.size {
if _, err := f.fsys.helper("truncate", f.path, fmt.Sprintf("%d", f.pos)); err != nil {
if _, err := f.fsys.helper("truncate", f.path, strconv.FormatInt(f.pos, 10)); err != nil {
return 0, fmt.Errorf("%w: truncate %s for writing: %w", ErrCommandFailed, f.path, err)
}
ddCmd = fmt.Sprintf("dd if=/dev/stdin of=%s bs=16M oflag=append conv=notrunc", shellescape.Quote(f.path))
Expand Down
Loading