Skip to content

Commit

Permalink
Add StartExecNonBlocking
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Wilkie committed Dec 8, 2015
1 parent 20318e4 commit 3392218
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,40 @@ func (c *Client) StartExec(id string, opts StartExecOptions) error {
return cw.Wait()
}

// StartExecNonBlocking starts a previously set up exec instance id. If opts.Detach is
// true, it returns after starting the exec command. Otherwise, it sets up an
// interactive session with the exec command.
//
// See https://goo.gl/iQCnto for more details
func (c *Client) StartExecNonBlocking(id string, opts StartExecOptions) (CloseWaiter, error) {
if id == "" {
return nil, &NoSuchExec{ID: id}
}

path := fmt.Sprintf("/exec/%s/start", id)

if opts.Detach {
resp, err := c.do("POST", path, doOptions{data: opts})
if err != nil {
if e, ok := err.(*Error); ok && e.Status == http.StatusNotFound {
return nil, &NoSuchExec{ID: id}
}
return nil, err
}
defer resp.Body.Close()
return nil, nil
}

return c.hijack("POST", path, hijackOptions{
success: opts.Success,
setRawTerminal: opts.RawTerminal,
in: opts.InputStream,
stdout: opts.OutputStream,
stderr: opts.ErrorStream,
data: opts,
})
}

// ResizeExecTTY resizes the tty session used by the exec command id. This API
// is valid only if Tty was specified as part of creating and starting the exec
// command.
Expand Down

0 comments on commit 3392218

Please sign in to comment.