Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion docs/stackit_beta_intake_runner_delete.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@ stackit beta intake runner delete RUNNER_ID [flags]
```
Delete an Intake Runner with ID "xxx"
$ stackit beta intake runner delete xxx
Delete an Intake Runner with ID "xxx", along with all associated Intakes and Intake Users that would stop the removal of the Intake
$ stackit beta intake runner delete xxx --force
```

### Options

```
-h, --help Help for "stackit beta intake runner delete"
--force When true, also removes all associated Intakes and Intake Users that would stop the removal of the Intake
-h, --help Help for "stackit beta intake runner delete"
```

### Options inherited from parent commands
Expand Down
18 changes: 18 additions & 0 deletions internal/cmd/beta/intake/runner/delete/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"

"github.com/stackitcloud/stackit-cli/internal/pkg/flags"
"github.com/stackitcloud/stackit-cli/internal/pkg/types"

"github.com/spf13/cobra"
Expand All @@ -22,12 +23,14 @@ import (

const (
runnerIdArg = "RUNNER_ID"
forceFlag = "force"
)

// inputModel struct holds all the input parameters for the command
type inputModel struct {
*globalflags.GlobalFlagModel
RunnerId string
Force bool
}

// NewCmd creates a new cobra command for deleting an Intake Runner
Expand All @@ -41,6 +44,9 @@ func NewCmd(p *types.CmdParams) *cobra.Command {
examples.NewExample(
`Delete an Intake Runner with ID "xxx"`,
`$ stackit beta intake runner delete xxx`),
examples.NewExample(
`Delete an Intake Runner with ID "xxx", along with all associated Intakes and Intake Users that would stop the removal of the Intake`,
`$ stackit beta intake runner delete xxx --force`),
),
RunE: func(cmd *cobra.Command, args []string) error {
ctx := context.Background()
Expand All @@ -56,6 +62,9 @@ func NewCmd(p *types.CmdParams) *cobra.Command {
}

prompt := fmt.Sprintf("Are you sure you want to delete Intake Runner %q?", model.RunnerId)
if model.Force {
prompt = fmt.Sprintf("%s This will also remove all Intakes and Intake Users that would stop the removal of the Intake", prompt)
}
err = p.Printer.PromptForConfirmation(prompt)
if err != nil {
return err
Expand Down Expand Up @@ -87,9 +96,14 @@ func NewCmd(p *types.CmdParams) *cobra.Command {
return nil
},
}
configureFlags(cmd)
return cmd
}

func configureFlags(cmd *cobra.Command) {
cmd.Flags().Bool(forceFlag, false, "When true, also removes all associated Intakes and Intake Users that would stop the removal of the Intake")
}

// parseInput parses the command arguments and flags into a standardized model
func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inputModel, error) {
runnerId := inputArgs[0]
Expand All @@ -102,6 +116,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu
model := inputModel{
GlobalFlagModel: globalFlags,
RunnerId: runnerId,
Force: flags.FlagToBoolValue(p, cmd, forceFlag),
}

p.DebugInputModel(model)
Expand All @@ -111,5 +126,8 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu
// buildRequest creates the API request to delete an Intake Runner
func buildRequest(ctx context.Context, model *inputModel, apiClient *intake.APIClient) intake.ApiDeleteIntakeRunnerRequest {
req := apiClient.DefaultAPI.DeleteIntakeRunner(ctx, model.ProjectId, model.Region, model.RunnerId)
if model.Force {
return req.Force(true)
}
return req
}
18 changes: 18 additions & 0 deletions internal/cmd/beta/intake/runner/delete/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,17 @@ func TestParseInput(t *testing.T) {
isValid: true,
expectedModel: fixtureInputModel(),
},
{
description: "with force",
argValues: fixtureArgValues(),
flagValues: fixtureFlagValues(func(flagValues map[string]string) {
flagValues[forceFlag] = "true"
}),
isValid: true,
expectedModel: fixtureInputModel(func(model *inputModel) {
model.Force = true
}),
},
{
description: "no arg values",
argValues: []string{},
Expand Down Expand Up @@ -140,6 +151,13 @@ func TestBuildRequest(t *testing.T) {
model: fixtureInputModel(),
expectedRequest: fixtureRequest(),
},
{
description: "with force",
model: fixtureInputModel(func(model *inputModel) {
model.Force = true
}),
expectedRequest: fixtureRequest().Force(true),
},
}

for _, tt := range tests {
Expand Down