diff --git a/api/client/func.go b/api/client/func.go index c83b59e4c..558236723 100644 --- a/api/client/func.go +++ b/api/client/func.go @@ -17,7 +17,7 @@ import ( "github.com/docker/engine-api/types/network" "github.com/docker/engine-api/types/strslice" "github.com/docker/go-connections/nat" - "github.com/docker/go-units" + units "github.com/docker/go-units" Cli "github.com/hyperhq/hypercli/cli" ropts "github.com/hyperhq/hypercli/opts" flag "github.com/hyperhq/hypercli/pkg/mflag" @@ -383,6 +383,8 @@ func (cli *DockerCli) CmdFuncInspect(args ...string) error { // Usage: hyper func call NAME func (cli *DockerCli) CmdFuncCall(args ...string) error { cmd := Cli.Subcmd("func call", []string{"NAME"}, "Call a function", false) + wait := cmd.Bool([]string{"-wait"}, false, "Block until the call is completed") + cmd.Require(flag.Exact, 1) if err := cmd.ParseFlags(args, true); err != nil { return err @@ -398,11 +400,24 @@ func (cli *DockerCli) CmdFuncCall(args ...string) error { } } - ret, err := cli.client.FuncCall(context.Background(), name, stdin) + body, err := cli.client.FuncCall(context.Background(), name, stdin, *wait) + if err != nil { + return err + } + defer body.Close() + + if *wait { + _, err = io.Copy(cli.out, body) + return err + } + + var ret types.FuncCallResponse + err = json.NewDecoder(body).Decode(&ret) if err != nil { return err } fmt.Fprintf(cli.out, "CallId: %s\n", ret.CallId) + return nil } @@ -424,9 +439,7 @@ func (cli *DockerCli) CmdFuncGet(args ...string) error { if err != nil { return err } - defer func() { - body.Close() - }() + defer body.Close() _, err = io.Copy(cli.out, body) return err diff --git a/vendor/src/github.com/docker/engine-api/client/func.go b/vendor/src/github.com/docker/engine-api/client/func.go index 2f2ab35f5..4571fb83d 100644 --- a/vendor/src/github.com/docker/engine-api/client/func.go +++ b/vendor/src/github.com/docker/engine-api/client/func.go @@ -182,26 +182,24 @@ func (cli *Client) FuncInspectWithCallId(ctx context.Context, id string) (*types return &fn, err } -func (cli *Client) FuncCall(ctx context.Context, name string, stdin io.Reader) (*types.FuncCallResponse, error) { +func (cli *Client) FuncCall(ctx context.Context, name string, stdin io.Reader, wait bool) (io.ReadCloser, error) { fn, _, err := cli.FuncInspectWithRaw(ctx, name) if err != nil { return nil, err } - req, err := newFuncEndpointRequest("POST", path.Join("call", name, fn.UUID), nil, stdin) - if err != nil { - return nil, err + subpath := "" + if wait { + subpath += "/wait" } - resp, err := funcEndpointRequest(req) + req, err := newFuncEndpointRequest("POST", path.Join("call", name, fn.UUID, subpath), nil, stdin) if err != nil { return nil, err } - defer resp.Body.Close() - var ret types.FuncCallResponse - err = json.NewDecoder(resp.Body).Decode(&ret) + resp, err := funcEndpointRequest(req) if err != nil { return nil, err } - return &ret, nil + return resp.Body, nil } func (cli *Client) FuncGet(ctx context.Context, callId string, wait bool) (io.ReadCloser, error) { diff --git a/vendor/src/github.com/docker/engine-api/client/interface.go b/vendor/src/github.com/docker/engine-api/client/interface.go index 29afb1a04..2e7992860 100644 --- a/vendor/src/github.com/docker/engine-api/client/interface.go +++ b/vendor/src/github.com/docker/engine-api/client/interface.go @@ -126,7 +126,7 @@ type APIClient interface { FuncList(ctx context.Context, opts types.FuncListOptions) ([]types.Func, error) FuncInspect(ctx context.Context, name string) (types.Func, error) FuncInspectWithRaw(ctx context.Context, name string) (types.Func, []byte, error) - FuncCall(ctx context.Context, name string, stdin io.Reader) (*types.FuncCallResponse, error) + FuncCall(ctx context.Context, name string, stdin io.Reader, wait bool) (io.ReadCloser, error) FuncGet(ctx context.Context, callId string, wait bool) (io.ReadCloser, error) FuncLogs(ctx context.Context, name, callId string, follow bool, tail string) (io.ReadCloser, error) FuncStatus(ctx context.Context, name string) (*types.FuncStatusResponse, error)