diff --git a/cmd/switch.go b/cmd/switch.go index d9fb46f5..58927825 100644 --- a/cmd/switch.go +++ b/cmd/switch.go @@ -11,6 +11,7 @@ import ( "github.com/metal-stack/metal-go/api/models" "github.com/metal-stack/metal-lib/pkg/genericcli" "github.com/metal-stack/metal-lib/pkg/genericcli/printers" + "github.com/metal-stack/metal-lib/pkg/pointer" "github.com/metal-stack/metalctl/cmd/sorters" "github.com/metal-stack/metalctl/cmd/tableprinters" "github.com/spf13/cobra" @@ -59,6 +60,9 @@ func newSwitchCmd(c *config) *cobra.Command { genericcli.Must(cmd.RegisterFlagCompletionFunc("os-vendor", c.comp.SwitchOSVendorListCompletion)) genericcli.Must(cmd.RegisterFlagCompletionFunc("os-version", c.comp.SwitchOSVersionListCompletion)) }, + DeleteCmdMutateFn: func(cmd *cobra.Command) { + cmd.Flags().Bool("force", false, "forcefully delete the switch accepting the risk that it still has machines connected to it") + }, } switchDetailCmd := &cobra.Command{ @@ -222,7 +226,7 @@ func (c switchCmd) List() ([]*models.V1SwitchResponse, error) { } func (c switchCmd) Delete(id string) (*models.V1SwitchResponse, error) { - resp, err := c.client.SwitchOperations().DeleteSwitch(switch_operations.NewDeleteSwitchParams().WithID(id), nil) + resp, err := c.client.SwitchOperations().DeleteSwitch(switch_operations.NewDeleteSwitchParams().WithID(id).WithForce(pointer.Pointer(viper.GetBool("force"))), nil) if err != nil { return nil, err } diff --git a/go.mod b/go.mod index 8a847fd9..fa64f7d1 100644 --- a/go.mod +++ b/go.mod @@ -175,3 +175,5 @@ require ( sigs.k8s.io/yaml v1.4.0 // indirect tailscale.com v1.54.1 // indirect ) + +replace github.com/metal-stack/metal-go v0.32.0 => ../metal-go diff --git a/go.sum b/go.sum index 28ac93ab..327bcb44 100644 --- a/go.sum +++ b/go.sum @@ -235,8 +235,6 @@ github.com/mdlayher/sdnotify v1.0.0 h1:Ma9XeLVN/l0qpyx1tNeMSeTjCPH6NtuD6/N9XdTlQ github.com/mdlayher/sdnotify v1.0.0/go.mod h1:HQUmpM4XgYkhDLtd+Uad8ZFK1T9D5+pNxnXQjCeJlGE= github.com/mdlayher/socket v0.5.1 h1:VZaqt6RkGkt2OE9l3GcC6nZkqD3xKeQLyfleW/uBcos= github.com/mdlayher/socket v0.5.1/go.mod h1:TjPLHI1UgwEv5J1B5q0zTZq12A/6H7nKmtTanQE37IQ= -github.com/metal-stack/metal-go v0.32.0 h1:8wpKkyx36qw4oKB0tt/95uENrw40DkCFbjq7bFz3KMs= -github.com/metal-stack/metal-go v0.32.0/go.mod h1:3MJTYCS4YJz8D8oteTKhjpaAKNMMjMKYDrIy9awHGtQ= github.com/metal-stack/metal-lib v0.17.0 h1:0fCRUtYweJ5wbUwiEalFGiHkEz0mZwTWQUIIo3Npzkw= github.com/metal-stack/metal-lib v0.17.0/go.mod h1:nyNGI4DZFOcWbSoq2Y6V3SHpFxuXBIqYBZHTb6cy//s= github.com/metal-stack/security v0.8.0 h1:tVaSDB9m5clwYrnLyaXfPy7mQlJTnmeoHscG+RUy/xo=