Skip to content

Commit a997083

Browse files
author
Matthew Fisher
committed
fix(deisctl): fixup most of go vet errors
1 parent 1a0dc0b commit a997083

2 files changed

Lines changed: 12 additions & 12 deletions

File tree

deisctl/backend/fleet/ssh.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
func runCommand(cmd string, machID string) (retcode int) {
1818
var err error
1919
if machine.IsLocalMachineID(machID) {
20-
err, retcode = runLocalCommand(cmd)
20+
retcode, err = runLocalCommand(cmd)
2121
if err != nil {
2222
fmt.Printf("Error running local command: %v\n", err)
2323
}
@@ -27,7 +27,7 @@ func runCommand(cmd string, machID string) (retcode int) {
2727
fmt.Printf("Error getting machine IP: %v\n", err)
2828
} else {
2929
sshTimeout := time.Duration(Flags.SSHTimeout*1000) * time.Millisecond
30-
err, retcode = runRemoteCommand(cmd, ms.PublicIP, sshTimeout)
30+
retcode, err = runRemoteCommand(cmd, ms.PublicIP, sshTimeout)
3131
if err != nil {
3232
fmt.Printf("Error running remote command: %v\n", err)
3333
}
@@ -37,7 +37,7 @@ func runCommand(cmd string, machID string) (retcode int) {
3737
}
3838

3939
// runLocalCommand runs the given command locally and returns any error encountered and the exit code of the command
40-
func runLocalCommand(cmd string) (error, int) {
40+
func runLocalCommand(cmd string) (int, error) {
4141
cmdSlice := strings.Split(cmd, " ")
4242
osCmd := exec.Command(cmdSlice[0], cmdSlice[1:]...)
4343
osCmd.Stderr = os.Stderr
@@ -48,31 +48,32 @@ func runLocalCommand(cmd string) (error, int) {
4848
// Get the command's exit status if we can
4949
if exiterr, ok := err.(*exec.ExitError); ok {
5050
if status, ok := exiterr.Sys().(syscall.WaitStatus); ok {
51-
return nil, status.ExitStatus()
51+
return status.ExitStatus(), nil
5252
}
5353
}
5454
// Otherwise, generic command error
55-
return err, -1
55+
return -1, err
5656
}
57-
return nil, 0
57+
return 0, nil
5858
}
5959

6060
// runRemoteCommand runs the given command over SSH on the given IP, and returns
6161
// any error encountered and the exit status of the command
62-
func runRemoteCommand(cmd string, addr string, timeout time.Duration) (err error, exit int) {
62+
func runRemoteCommand(cmd string, addr string, timeout time.Duration) (exit int, err error) {
6363
var sshClient *ssh.SSHForwardingClient
6464
if tun := getTunnelFlag(); tun != "" {
6565
sshClient, err = ssh.NewTunnelledSSHClient("core", tun, addr, getChecker(), false, timeout)
6666
} else {
6767
sshClient, err = ssh.NewSSHClient("core", addr, getChecker(), false, timeout)
6868
}
6969
if err != nil {
70-
return err, -1
70+
return -1, err
7171
}
7272

7373
defer sshClient.Close()
7474

75-
return ssh.Execute(sshClient, cmd)
75+
err, exit = ssh.Execute(sshClient, cmd)
76+
return
7677
}
7778

7879
func machineState(machID string) (*machine.MachineState, error) {

deisctl/deisctl.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,8 @@ Options:
6767
if helpFlag {
6868
fmt.Print(usage)
6969
return 0
70-
} else {
71-
return 1
7270
}
71+
return 1
7372
}
7473
command := args["<command>"]
7574
setTunnel := true
@@ -185,7 +184,7 @@ func parseArgs(argv []string) ([]string, bool) {
185184
// removeGlobalArgs returns the given args without any global option flags, to make
186185
// re-parsing by subcommands easier.
187186
func removeGlobalArgs(argv []string) []string {
188-
v := make([]string, 0)
187+
var v []string
189188
for _, a := range argv {
190189
if !isGlobalArg(a) {
191190
v = append(v, a)

0 commit comments

Comments
 (0)