Command returns the ssh flags and arguments to execute a command (remoteCommandAndArgs) on the remote host. Where needed, it quotes values passed in remoteCommandAndArgs to account for ssh executing the remote command in a shell. It returns an error if no remote command is passed, or when unable to
(sshFlags []string, remoteCommandAndArgs ...string)
| 144 | // perform sanitization or quoting on the sshFlags and callers are expected |
| 145 | // to sanitize this argument. |
| 146 | func (sp *Spec) Command(sshFlags []string, remoteCommandAndArgs ...string) ([]string, error) { |
| 147 | if len(remoteCommandAndArgs) == 0 { |
| 148 | return nil, errors.New("no remote command specified") |
| 149 | } |
| 150 | sshArgs, err := sp.args(sshFlags...) |
| 151 | if err != nil { |
| 152 | return nil, err |
| 153 | } |
| 154 | remoteCommand, err := quoteCommand(remoteCommandAndArgs...) |
| 155 | if err != nil { |
| 156 | return nil, err |
| 157 | } |
| 158 | if remoteCommand != "" { |
| 159 | sshArgs = append(sshArgs, remoteCommand) |
| 160 | } |
| 161 | return sshArgs, nil |
| 162 | } |
| 163 | |
| 164 | // quoteCommand returns the remote command to run using the ssh connection |
| 165 | // as a single string, quoting values where needed because ssh executes |