From 71a3f8966de2d722ab6e6772d5398d30ea27610b Mon Sep 17 00:00:00 2001 From: Roger Zaragoza Ripoll Date: Thu, 18 Jun 2026 12:14:02 +0200 Subject: [PATCH] feat(intake): add force flag for deleting intake runners Adds a flag to enable calling delete intake runner API with force flag. relates to STACKITINT-1392 --- docs/stackit_beta_intake_runner_delete.md | 6 +++++- .../cmd/beta/intake/runner/delete/delete.go | 18 ++++++++++++++++++ .../beta/intake/runner/delete/delete_test.go | 18 ++++++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/docs/stackit_beta_intake_runner_delete.md b/docs/stackit_beta_intake_runner_delete.md index 0fa94ae5f..c97d388cd 100644 --- a/docs/stackit_beta_intake_runner_delete.md +++ b/docs/stackit_beta_intake_runner_delete.md @@ -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 diff --git a/internal/cmd/beta/intake/runner/delete/delete.go b/internal/cmd/beta/intake/runner/delete/delete.go index 794122083..40b1142e3 100644 --- a/internal/cmd/beta/intake/runner/delete/delete.go +++ b/internal/cmd/beta/intake/runner/delete/delete.go @@ -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" @@ -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 @@ -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() @@ -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 @@ -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] @@ -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) @@ -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 } diff --git a/internal/cmd/beta/intake/runner/delete/delete_test.go b/internal/cmd/beta/intake/runner/delete/delete_test.go index a4d5048fd..7ffb4b555 100644 --- a/internal/cmd/beta/intake/runner/delete/delete_test.go +++ b/internal/cmd/beta/intake/runner/delete/delete_test.go @@ -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{}, @@ -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 {