MCPcopy Index your code
hub / github.com/cli/cli / newSSHCommand

Function newSSHCommand

internal/codespaces/ssh.go:65–91  ·  view source on GitHub ↗

newSSHCommand populates an exec.Cmd to run a command (or if blank, an interactive shell) over ssh.

(ctx context.Context, port int, dst string, cmdArgs []string, command []string)

Source from the content-addressed store, hash-verified

63// newSSHCommand populates an exec.Cmd to run a command (or if blank,
64// an interactive shell) over ssh.
65func newSSHCommand(ctx context.Context, port int, dst string, cmdArgs []string, command []string) (*exec.Cmd, []string, error) {
66 connArgs := []string{
67 "-p", strconv.Itoa(port),
68 "-o", "NoHostAuthenticationForLocalhost=yes",
69 "-o", "PasswordAuthentication=no",
70 }
71
72 cmdArgs = append(cmdArgs, connArgs...)
73 cmdArgs = append(cmdArgs, "-C") // Compression
74 cmdArgs = append(cmdArgs, dst) // user@host
75
76 if command != nil {
77 cmdArgs = append(cmdArgs, command...)
78 }
79
80 exe, err := safeexec.LookPath("ssh")
81 if err != nil {
82 return nil, nil, fmt.Errorf("failed to execute ssh: %w", err)
83 }
84
85 cmd := exec.CommandContext(ctx, exe, cmdArgs...)
86 cmd.Stdout = os.Stdout
87 cmd.Stdin = os.Stdin
88 cmd.Stderr = os.Stderr
89
90 return cmd, connArgs, nil
91}
92
93// ParseSSHArgs parses the given array of arguments into two distinct slices of flags and command.
94// The ssh command syntax is: ssh [flags] user@host command [args...]

Callers 2

ShellFunction · 0.85
NewRemoteCommandFunction · 0.85

Calls 1

ErrorfMethod · 0.65

Tested by

no test coverage detected