diff --git a/internal/cmd/commands/ferry/pause.go b/internal/cmd/commands/ferry/pause.go index bddafae5e8..05fb462bce 100644 --- a/internal/cmd/commands/ferry/pause.go +++ b/internal/cmd/commands/ferry/pause.go @@ -90,8 +90,13 @@ func (c *PauseCommand) Run(args []string) int { return base.CommandApiError } - if resp.StatusCode() != 200 { - return base.CommandCliError + switch base.Format(c.UI) { + case "json": + if ok := c.PrintJsonItem(resp); !ok { + return base.CommandCliError + } + default: + c.UI.Output("Ferry has been successfully paused.") } return base.CommandSuccess } @@ -118,5 +123,14 @@ func (c *PauseCommand) Pause(ctx context.Context) (*api.Response, *api.Error, er return nil, nil, errors.Wrap(ctx, err, op, errors.WithMsg("client do failed")) } apiResp := api.NewResponse(resp) + + apiErr, err := apiResp.Decode(nil) + if err != nil { + return nil, nil, errors.Wrap(ctx, err, op, errors.WithMsg("error decoding Resume response")) + } + if apiErr != nil { + return nil, apiErr, nil + } + return apiResp, nil, nil } diff --git a/internal/cmd/commands/ferry/resume.go b/internal/cmd/commands/ferry/resume.go index ff5e944005..c274f8870a 100644 --- a/internal/cmd/commands/ferry/resume.go +++ b/internal/cmd/commands/ferry/resume.go @@ -90,8 +90,13 @@ func (c *ResumeCommand) Run(args []string) int { return base.CommandApiError } - if resp.StatusCode() != 200 { - return base.CommandCliError + switch base.Format(c.UI) { + case "json": + if ok := c.PrintJsonItem(resp); !ok { + return base.CommandCliError + } + default: + c.UI.Output("Ferry has been successfully resumed.") } return base.CommandSuccess } @@ -118,5 +123,14 @@ func (c *ResumeCommand) Resume(ctx context.Context) (*api.Response, *api.Error, return nil, nil, errors.Wrap(ctx, err, op, errors.WithMsg("client do failed")) } apiResp := api.NewResponse(resp) + + apiErr, err := apiResp.Decode(nil) + if err != nil { + return nil, nil, errors.Wrap(ctx, err, op, errors.WithMsg("error decoding Resume response")) + } + if apiErr != nil { + return nil, apiErr, nil + } + return apiResp, nil, nil } diff --git a/internal/cmd/commands/ferry/status.go b/internal/cmd/commands/ferry/status.go index d04a732257..bd7f388d10 100644 --- a/internal/cmd/commands/ferry/status.go +++ b/internal/cmd/commands/ferry/status.go @@ -107,6 +107,7 @@ type GetStatusResponse struct { AuthTokenId string `json:"auth_token_id"` AuthTokenExpiry time.Time `json:"auth_token_expiry"` Version string `json:"version"` + Status string `json:"status"` Errors []string `json:"errors"` Warnings []string `json:"warnings"` } @@ -138,7 +139,7 @@ func (c *StatusCommand) Status(ctx context.Context) (*api.Response, *GetStatusRe res := &GetStatusResponse{} apiErr, err := apiResp.Decode(&res) if err != nil { - return nil, nil, nil, fmt.Errorf("Error when sending request to the ferry daemon: %w.", err) + return nil, nil, nil, fmt.Errorf("error when sending request to the ferry daemon: %w", err) } if apiErr != nil { return apiResp, nil, apiErr, nil @@ -152,6 +153,7 @@ func printStatusTable(status *GetStatusResponse) string { "Auth Token Id": status.AuthTokenId, "Auth Token Expiration": time.Until(status.AuthTokenExpiry).Round(time.Second).String(), "Version": status.Version, + "Status": status.Status, } maxLength := base.MaxAttributesLength(nonAttributeMap, nil, nil)