{"record":{"id":"395e7a12266b2325","repo":"docker/cli","slug":"no-remote-command-specified","errorCode":null,"errorMessage":"no remote command specified","messagePattern":"no remote command specified","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/connhelper/ssh/ssh.go","lineNumber":148,"sourceCode":"\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"invalid host: %w\", err)\n\t}\n\n\treturn append(args, \"--\", host), nil\n}\n\n// Command returns the ssh flags and arguments to execute a command\n// (remoteCommandAndArgs) on the remote host. Where needed, it quotes\n// values passed in remoteCommandAndArgs to account for ssh executing\n// the remote command in a shell. It returns an error if no remote command\n// is passed, or when unable to quote the remote command.\n//\n// Important: to preserve backward-compatibility, Command does not currently\n// perform sanitization or quoting on the sshFlags and callers are expected\n// to sanitize this argument.\nfunc (sp *Spec) Command(sshFlags []string, remoteCommandAndArgs ...string) ([]string, error) {\n\tif len(remoteCommandAndArgs) == 0 {\n\t\treturn nil, errors.New(\"no remote command specified\")\n\t}\n\tsshArgs, err := sp.args(sshFlags...)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tremoteCommand, err := quoteCommand(remoteCommandAndArgs...)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tif remoteCommand != \"\" {\n\t\tsshArgs = append(sshArgs, remoteCommand)\n\t}\n\treturn sshArgs, nil\n}\n\n// quoteCommand returns the remote command to run using the ssh connection\n// as a single string, quoting values where needed because ssh executes\n// these in a POSIX shell.","sourceCodeStart":130,"sourceCodeEnd":166,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/cli/connhelper/ssh/ssh.go#L130-L166","documentation":"Returned by Spec.Command when remoteCommandAndArgs is empty. Unlike Spec.Args (which builds the connection args only), Command is meant to produce a full ssh invocation that runs a remote command, so it requires at least one command token. Without a command there is nothing to execute on the remote host.","triggerScenarios":"Calling spec.Command(sshFlags) with no variadic command arguments, or passing an empty slice. Using Command where Args was intended.","commonSituations":"A caller wires up Command for a dialer that only needs the connection arguments and forgets to supply the remote command. Misreading the API and assuming sshFlags are the command.","solutions":["Pass the remote command as the variadic args, e.g. spec.Command([]string{\"-o\", \"...\"}, \"docker\", \"context\", \"update\").","If you only need connection arguments (no remote command), call spec.Args(...) instead.","Guard the call site: only invoke Command when you have a non-empty command to run."],"exampleFix":"// before\nargs, err := spec.Command([]string{\"-o\", \"StrictHostKeyChecking=no\"})\n// after\nargs, err := spec.Command([]string{\"-o\", \"StrictHostKeyChecking=no\"}, \"docker\", \"system\", \"dial-stdio\")","handlingStrategy":"validation","validationCode":"if len(remoteCmd) == 0 {\n    args, err := spec.Args(sshFlags...) // use Args when no command\n} else {\n    args, err := spec.Command(sshFlags, remoteCmd...)\n}","typeGuard":"func hasRemoteCommand(cmd []string) bool { return len(cmd) > 0 }","tryCatchPattern":null,"preventionTips":["Use Spec.Args when you only need connection arguments.","Reserve Spec.Command for cases with an actual remote command.","Guard with len(remoteCommandAndArgs) > 0 before calling Command."],"tags":["ssh","connhelper","api-usage","validation"],"backgroundTag":null,"analyzedSha":"4f84911bfe8811e9b028e4b1fee8e7510be79387","analyzedAt":"2026-08-07T12:15:29.814Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}