MCPcopy Index your code
hub / github.com/docker/cli / quoteCommand

Function quoteCommand

cli/connhelper/ssh/ssh.go:167–183  ·  view source on GitHub ↗

quoteCommand returns the remote command to run using the ssh connection as a single string, quoting values where needed because ssh executes these in a POSIX shell.

(commandAndArgs ...string)

Source from the content-addressed store, hash-verified

165// as a single string, quoting values where needed because ssh executes
166// these in a POSIX shell.
167func quoteCommand(commandAndArgs ...string) (string, error) {
168 var quotedCmd string
169 for i, arg := range commandAndArgs {
170 a, err := syntax.Quote(arg, syntax.LangPOSIX)
171 if err != nil {
172 return "", fmt.Errorf("invalid argument: %w", err)
173 }
174 if i == 0 {
175 quotedCmd = a
176 continue
177 }
178 quotedCmd += " " + a
179 }
180 // each part is quoted appropriately, so now we'll have a full
181 // shell command to pass off to "ssh"
182 return quotedCmd, nil
183}

Callers 2

ArgsMethod · 0.85
CommandMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…