Skip to content

Commit

Permalink
fix(deisctl): fixup most of go vet errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Fisher committed Dec 18, 2014
1 parent 1a0dc0b commit a997083
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
19 changes: 10 additions & 9 deletions deisctl/backend/fleet/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
func runCommand(cmd string, machID string) (retcode int) {
var err error
if machine.IsLocalMachineID(machID) {
err, retcode = runLocalCommand(cmd)
retcode, err = runLocalCommand(cmd)
if err != nil {
fmt.Printf("Error running local command: %v\n", err)
}
Expand All @@ -27,7 +27,7 @@ func runCommand(cmd string, machID string) (retcode int) {
fmt.Printf("Error getting machine IP: %v\n", err)
} else {
sshTimeout := time.Duration(Flags.SSHTimeout*1000) * time.Millisecond
err, retcode = runRemoteCommand(cmd, ms.PublicIP, sshTimeout)
retcode, err = runRemoteCommand(cmd, ms.PublicIP, sshTimeout)
if err != nil {
fmt.Printf("Error running remote command: %v\n", err)
}
Expand All @@ -37,7 +37,7 @@ func runCommand(cmd string, machID string) (retcode int) {
}

// runLocalCommand runs the given command locally and returns any error encountered and the exit code of the command
func runLocalCommand(cmd string) (error, int) {
func runLocalCommand(cmd string) (int, error) {
cmdSlice := strings.Split(cmd, " ")
osCmd := exec.Command(cmdSlice[0], cmdSlice[1:]...)
osCmd.Stderr = os.Stderr
Expand All @@ -48,31 +48,32 @@ func runLocalCommand(cmd string) (error, int) {
// Get the command's exit status if we can
if exiterr, ok := err.(*exec.ExitError); ok {
if status, ok := exiterr.Sys().(syscall.WaitStatus); ok {
return nil, status.ExitStatus()
return status.ExitStatus(), nil
}
}
// Otherwise, generic command error
return err, -1
return -1, err
}
return nil, 0
return 0, nil
}

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

defer sshClient.Close()

return ssh.Execute(sshClient, cmd)
err, exit = ssh.Execute(sshClient, cmd)
return
}

func machineState(machID string) (*machine.MachineState, error) {
Expand Down
5 changes: 2 additions & 3 deletions deisctl/deisctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,8 @@ Options:
if helpFlag {
fmt.Print(usage)
return 0
} else {
return 1
}
return 1
}
command := args["<command>"]
setTunnel := true
Expand Down Expand Up @@ -185,7 +184,7 @@ func parseArgs(argv []string) ([]string, bool) {
// removeGlobalArgs returns the given args without any global option flags, to make
// re-parsing by subcommands easier.
func removeGlobalArgs(argv []string) []string {
v := make([]string, 0)
var v []string
for _, a := range argv {
if !isGlobalArg(a) {
v = append(v, a)
Expand Down

0 comments on commit a997083

Please sign in to comment.