diff --git a/internal/cmd/commands/ferry/pause.go b/internal/cmd/commands/ferry/pause.go index 6e04e1df86..bddafae5e8 100644 --- a/internal/cmd/commands/ferry/pause.go +++ b/internal/cmd/commands/ferry/pause.go @@ -5,7 +5,6 @@ package ferry import ( "context" - "fmt" "strings" "time" @@ -45,7 +44,24 @@ Usage: boundary ferry pause } func (c *PauseCommand) Flags() *base.FlagSets { - return c.FlagSet(base.FlagSetNone) + set := c.FlagSet(base.FlagSetOutputFormat) + f := set.NewFlagSet("Client Options") + + f.BoolVar(&base.BoolVar{ + Name: "output-curl-string", + Target: &c.FlagOutputCurlString, + Usage: "Instead of executing the request, print an equivalent cURL command string and exit.", + }) + + f.UintVar(&base.UintVar{ + Name: "ferry-port", + Target: &c.FlagFerryDaemonPort, + Default: 9300, + EnvVar: base.EnvFerryDaemonPort, + Usage: "The port on which the ferry daemon is listening.", + }) + + return set } func (c *PauseCommand) AutocompleteArgs() complete.Predictor { @@ -58,6 +74,11 @@ func (c *PauseCommand) AutocompleteFlags() complete.Flags { func (c *PauseCommand) Run(args []string) int { ctx := c.Context + f := c.Flags() + if err := f.Parse(args); err != nil { + c.PrintCliError(err) + return base.CommandUserError + } resp, apiErr, err := c.Pause(ctx) if err != nil { @@ -69,14 +90,14 @@ func (c *PauseCommand) Run(args []string) int { return base.CommandApiError } - if ok := c.PrintJsonItem(resp); !ok { + if resp.StatusCode() != 200 { return base.CommandCliError } return base.CommandSuccess } func (c *PauseCommand) Pause(ctx context.Context) (*api.Response, *api.Error, error) { - const op = "ferry.(PauseCommand).Status" + const op = "ferry.(PauseCommand).Pause" client := retryablehttp.NewClient() client.Logger = nil client.RetryWaitMin = 100 * time.Millisecond @@ -86,7 +107,6 @@ func (c *PauseCommand) Pause(ctx context.Context) (*api.Response, *api.Error, er if err != nil { return nil, nil, err } - req.Header.Set("content-type", "application/json") if c.FlagOutputCurlString { api.LastOutputStringError = &api.OutputStringError{Request: req} @@ -98,14 +118,5 @@ 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) - - res := &GetStatusResponse{} - apiErr, err := apiResp.Decode(&res) - if err != nil { - return nil, nil, fmt.Errorf("error when sending request to the ferry daemon: %w", err) - } - if apiErr != nil { - return apiResp, apiErr, nil - } return apiResp, nil, nil } diff --git a/internal/cmd/commands/ferry/resume.go b/internal/cmd/commands/ferry/resume.go index 1d723ffb5b..ff5e944005 100644 --- a/internal/cmd/commands/ferry/resume.go +++ b/internal/cmd/commands/ferry/resume.go @@ -5,7 +5,6 @@ package ferry import ( "context" - "fmt" "strings" "time" @@ -45,7 +44,24 @@ Usage: boundary ferry resume } func (c *ResumeCommand) Flags() *base.FlagSets { - return c.FlagSet(base.FlagSetNone) + set := c.FlagSet(base.FlagSetOutputFormat) + f := set.NewFlagSet("Client Options") + + f.BoolVar(&base.BoolVar{ + Name: "output-curl-string", + Target: &c.FlagOutputCurlString, + Usage: "Instead of executing the request, print an equivalent cURL command string and exit.", + }) + + f.UintVar(&base.UintVar{ + Name: "ferry-port", + Target: &c.FlagFerryDaemonPort, + Default: 9300, + EnvVar: base.EnvFerryDaemonPort, + Usage: "The port on which the ferry daemon is listening.", + }) + + return set } func (c *ResumeCommand) AutocompleteArgs() complete.Predictor { @@ -58,6 +74,11 @@ func (c *ResumeCommand) AutocompleteFlags() complete.Flags { func (c *ResumeCommand) Run(args []string) int { ctx := c.Context + f := c.Flags() + if err := f.Parse(args); err != nil { + c.PrintCliError(err) + return base.CommandUserError + } resp, apiErr, err := c.Resume(ctx) if err != nil { @@ -69,14 +90,14 @@ func (c *ResumeCommand) Run(args []string) int { return base.CommandApiError } - if ok := c.PrintJsonItem(resp); !ok { + if resp.StatusCode() != 200 { return base.CommandCliError } return base.CommandSuccess } func (c *ResumeCommand) Resume(ctx context.Context) (*api.Response, *api.Error, error) { - const op = "ferry.(ResumeCommand).Status" + const op = "ferry.(ResumeCommand).Resume" client := retryablehttp.NewClient() client.Logger = nil client.RetryWaitMin = 100 * time.Millisecond @@ -86,7 +107,6 @@ func (c *ResumeCommand) Resume(ctx context.Context) (*api.Response, *api.Error, if err != nil { return nil, nil, err } - req.Header.Set("content-type", "application/json") if c.FlagOutputCurlString { api.LastOutputStringError = &api.OutputStringError{Request: req} @@ -98,14 +118,5 @@ 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) - - res := &GetStatusResponse{} - apiErr, err := apiResp.Decode(&res) - if err != nil { - return nil, nil, fmt.Errorf("error when sending request to the ferry daemon: %w", err) - } - if apiErr != nil { - return apiResp, apiErr, nil - } return apiResp, nil, nil } diff --git a/internal/cmd/ferry_cmd_darwin.go b/internal/cmd/ferry_cmd_darwin.go index 91568037fd..e7e7d742f4 100644 --- a/internal/cmd/ferry_cmd_darwin.go +++ b/internal/cmd/ferry_cmd_darwin.go @@ -21,5 +21,15 @@ func init() { Command: base.NewCommand(ui), }, nil } + Commands["ferry pause"] = func() (cli.Command, error) { + return &ferry.PauseCommand{ + Command: base.NewCommand(ui), + }, nil + } + Commands["ferry resume"] = func() (cli.Command, error) { + return &ferry.ResumeCommand{ + Command: base.NewCommand(ui), + }, nil + } }) } diff --git a/internal/cmd/ferry_cmd_windows.go b/internal/cmd/ferry_cmd_windows.go index 55df18e3b5..1919873103 100644 --- a/internal/cmd/ferry_cmd_windows.go +++ b/internal/cmd/ferry_cmd_windows.go @@ -23,5 +23,15 @@ func init() { Command: base.NewCommand(ui), }, nil } + Commands["ferry pause"] = func() (cli.Command, error) { + return &ferry.PauseCommand{ + Command: base.NewCommand(ui), + }, nil + } + Commands["ferry resume"] = func() (cli.Command, error) { + return &ferry.ResumeCommand{ + Command: base.NewCommand(ui), + }, nil + } }) } diff --git a/internal/cmd/main.go b/internal/cmd/main.go index a266a90a8e..27cc984e39 100644 --- a/internal/cmd/main.go +++ b/internal/cmd/main.go @@ -241,7 +241,7 @@ func RunCustom(args []string, runOpts *RunOptions) (exitCode int) { initCommands(ui, serverCmdUi, runOpts) - hiddenCommands := []string{"version", "ferry", "ferry status"} + hiddenCommands := []string{"version", "ferry", "ferry status", "ferry pause", "ferry resume"} cli := &cli.CLI{ Name: "boundary",