diff --git a/docs/metal_interconnections_delete.md b/docs/metal_interconnections_delete.md index 25baabf4..e8b0c17b 100644 --- a/docs/metal_interconnections_delete.md +++ b/docs/metal_interconnections_delete.md @@ -4,7 +4,7 @@ Deletes a interconnection. ### Synopsis -Deletes the specified interconnection. +Deletes the specified interconnection. Use --force to skip confirmation ``` metal interconnections delete -i [flags] @@ -15,11 +15,15 @@ metal interconnections delete -i [flags] ``` # Deletes the specified interconnection: metal interconnections delete -i 7ec86e23-8dcf-48ed-bd9b-c25c20958277 + > + ✔ Are you sure you want to delete device 7ec86e23-8dcf-48ed-bd9b-c25c20958277 [Y/n]: Y + ``` ### Options ``` + -f, --force Skips confirmation for the interconnection deletion. -h, --help help for delete -i, --id string The UUID of the interconnection. ``` diff --git a/internal/interconnections/delete.go b/internal/interconnections/delete.go index 2a59a9c1..4dd98b20 100644 --- a/internal/interconnections/delete.go +++ b/internal/interconnections/delete.go @@ -3,23 +3,44 @@ package interconnections import ( "context" "fmt" + "strings" "github.com/spf13/cobra" ) func (c *Client) Delete() *cobra.Command { - var connectionID string + var connectionID, confirmation string + var force bool deleteConnectionCmd := &cobra.Command{ Use: `delete -i `, Short: "Deletes a interconnection.", - Long: "Deletes the specified interconnection.", + Long: "Deletes the specified interconnection. Use --force to skip confirmation", Example: ` # Deletes the specified interconnection: - metal interconnections delete -i 7ec86e23-8dcf-48ed-bd9b-c25c20958277`, + metal interconnections delete -i 7ec86e23-8dcf-48ed-bd9b-c25c20958277 + > + ✔ Are you sure you want to delete device 7ec86e23-8dcf-48ed-bd9b-c25c20958277 [Y/n]: Y +`, RunE: func(cmd *cobra.Command, args []string) error { cmd.SilenceUsage = true + if !force { + fmt.Printf("Are you sure you want to delete device %s [Y/n]: ", connectionID) + + _, err := fmt.Scanln(&confirmation) + if err != nil { + fmt.Println("Error reading confirmation:", err) + return nil + } + + confirmation = strings.TrimSpace(strings.ToLower(confirmation)) + if confirmation != "yes" && confirmation != "y" { + fmt.Println("Interconnection deletion cancelled.") + return nil + } + } + _, _, err := c.Service.DeleteInterconnection(context.Background(), connectionID).Execute() if err != nil { return err @@ -31,6 +52,7 @@ func (c *Client) Delete() *cobra.Command { } deleteConnectionCmd.Flags().StringVarP(&connectionID, "id", "i", "", "The UUID of the interconnection.") + deleteConnectionCmd.Flags().BoolVarP(&force, "force", "f", false, "Skips confirmation for the interconnection deletion.") _ = deleteConnectionCmd.MarkFlagRequired("id") return deleteConnectionCmd diff --git a/test/e2e/devices/devicecreateflagstest/device_create_flags_test.go b/test/e2e/devices/devicecreateflagstest/device_create_flags_test.go index 8857d407..8aca8e61 100644 --- a/test/e2e/devices/devicecreateflagstest/device_create_flags_test.go +++ b/test/e2e/devices/devicecreateflagstest/device_create_flags_test.go @@ -41,7 +41,7 @@ func TestCli_Devices_Create_Flags(t *testing.T) { want: &cobra.Command{}, cmdFunc: func(t *testing.T, c *cobra.Command) { root := c.Root() - projectName := "metal-cli-device-create-flags" + helper.GenerateRandomString(5) + projectName := "metal-cli-device-create-flags-" + helper.GenerateRandomString(5) projectId, err = helper.CreateTestProject(t, projectName) t.Cleanup(func() { if err := helper.CleanTestProject(t, projectId); err != nil && diff --git a/test/e2e/devices/devicecreatetest/device_create_test.go b/test/e2e/devices/devicecreatetest/device_create_test.go index 4641af6c..ceb03b1b 100644 --- a/test/e2e/devices/devicecreatetest/device_create_test.go +++ b/test/e2e/devices/devicecreatetest/device_create_test.go @@ -43,7 +43,7 @@ func TestCli_Devices_Create(t *testing.T) { want: &cobra.Command{}, cmdFunc: func(t *testing.T, c *cobra.Command) { root := c.Root() - projectName := "metal-cli-device-create" + randomId + projectName := "metal-cli-device-create-" + randomId projectId, err = helper.CreateTestProject(t, projectName) t.Cleanup(func() { if err := helper.CleanTestProject(t, projectId); err != nil && @@ -57,7 +57,7 @@ func TestCli_Devices_Create(t *testing.T) { if len(projectId) != 0 { - deviceName := "metal-cli-create-dev" + randomId + deviceName := "metal-cli-create-dev-" + randomId root.SetArgs([]string{subCommand, "create", "-p", projectId, "-P", "m3.small.x86", "-m", "da", "-O", "ubuntu_20_04", "-H", deviceName}) rescueStdout := os.Stdout r, w, _ := os.Pipe() diff --git a/test/e2e/devices/devicegettest/device_get_test.go b/test/e2e/devices/devicegettest/device_get_test.go index 403398b8..4709c9d0 100644 --- a/test/e2e/devices/devicegettest/device_get_test.go +++ b/test/e2e/devices/devicegettest/device_get_test.go @@ -40,7 +40,7 @@ func TestCli_Devices_Get(t *testing.T) { want: &cobra.Command{}, cmdFunc: func(t *testing.T, c *cobra.Command) { root := c.Root() - projectName := "metal-cli-device-get" + helper.GenerateRandomString(5) + projectName := "metal-cli-device-get-" + helper.GenerateRandomString(5) projectId, err = helper.CreateTestProject(t, projectName) t.Cleanup(func() { if err := helper.CleanTestProject(t, projectId); err != nil && diff --git a/test/e2e/devices/devicereinstalltest/device_reinstall_test.go b/test/e2e/devices/devicereinstalltest/device_reinstall_test.go index 25161bce..c360d269 100644 --- a/test/e2e/devices/devicereinstalltest/device_reinstall_test.go +++ b/test/e2e/devices/devicereinstalltest/device_reinstall_test.go @@ -39,7 +39,7 @@ func TestCli_Devices_Update(t *testing.T) { want: &cobra.Command{}, cmdFunc: func(t *testing.T, c *cobra.Command) { root := c.Root() - projectName := "metal-cli-device-reinstall" + helper.GenerateRandomString(5) + projectName := "metal-cli-device-reinstall-" + helper.GenerateRandomString(5) projectId, err = helper.CreateTestProject(t, projectName) t.Cleanup(func() { if err := helper.CleanTestProject(t, projectId); err != nil && diff --git a/test/e2e/devices/devicestarttest/device_start_test.go b/test/e2e/devices/devicestarttest/device_start_test.go index 2f67223d..2876965d 100644 --- a/test/e2e/devices/devicestarttest/device_start_test.go +++ b/test/e2e/devices/devicestarttest/device_start_test.go @@ -41,7 +41,7 @@ func TestCli_Devices_Update(t *testing.T) { want: &cobra.Command{}, cmdFunc: func(t *testing.T, c *cobra.Command) { root := c.Root() - projectName := "metal-cli-device-start" + helper.GenerateRandomString(5) + projectName := "metal-cli-device-start-" + helper.GenerateRandomString(5) projectId, err = helper.CreateTestProject(t, projectName) t.Cleanup(func() { if err := helper.CleanTestProject(t, projectId); err != nil && diff --git a/test/e2e/devices/devicestoptest/device_stop_test.go b/test/e2e/devices/devicestoptest/device_stop_test.go index de52d074..ef12a598 100644 --- a/test/e2e/devices/devicestoptest/device_stop_test.go +++ b/test/e2e/devices/devicestoptest/device_stop_test.go @@ -40,7 +40,7 @@ func TestCli_Devices_Update(t *testing.T) { want: &cobra.Command{}, cmdFunc: func(t *testing.T, c *cobra.Command) { root := c.Root() - projectName := "metal-cli-device-stop" + helper.GenerateRandomString(5) + projectName := "metal-cli-device-stop-" + helper.GenerateRandomString(5) projectId, err = helper.CreateTestProject(t, projectName) t.Cleanup(func() { if err := helper.CleanTestProject(t, projectId); err != nil && diff --git a/test/e2e/devices/deviceupdatetest/device_update_test.go b/test/e2e/devices/deviceupdatetest/device_update_test.go index a5f9b8c0..14340330 100644 --- a/test/e2e/devices/deviceupdatetest/device_update_test.go +++ b/test/e2e/devices/deviceupdatetest/device_update_test.go @@ -40,7 +40,7 @@ func TestCli_Devices_Update(t *testing.T) { want: &cobra.Command{}, cmdFunc: func(t *testing.T, c *cobra.Command) { root := c.Root() - projectName := "metal-cli-device-update" + helper.GenerateRandomString(5) + projectName := "metal-cli-device-update-" + helper.GenerateRandomString(5) projectId, err = helper.CreateTestProject(t, projectName) t.Cleanup(func() { if err := helper.CleanTestProject(t, projectId); err != nil && diff --git a/test/e2e/events/deviceeventstest/device_event_test.go b/test/e2e/events/deviceeventstest/device_event_test.go index fa910da5..6800de79 100644 --- a/test/e2e/events/deviceeventstest/device_event_test.go +++ b/test/e2e/events/deviceeventstest/device_event_test.go @@ -41,7 +41,7 @@ func TestCli_Events_Get(t *testing.T) { want: &cobra.Command{}, cmdFunc: func(t *testing.T, c *cobra.Command) { root := c.Root() - projectName := "metal-cli-device-events" + helper.GenerateRandomString(5) + projectName := "metal-cli-device-events-" + helper.GenerateRandomString(5) projectId, err = helper.CreateTestProject(t, projectName) if err != nil { t.Error(err) diff --git a/test/e2e/events/projecteventstest/project_events_test.go b/test/e2e/events/projecteventstest/project_events_test.go index 6db71251..b5d69904 100644 --- a/test/e2e/events/projecteventstest/project_events_test.go +++ b/test/e2e/events/projecteventstest/project_events_test.go @@ -41,7 +41,7 @@ func TestCli_Events_Get(t *testing.T) { cmdFunc: func(t *testing.T, c *cobra.Command) { root := c.Root() - projectName := "metal-cli-projects-events" + helper.GenerateRandomString(5) + projectName := "metal-cli-projects-events-" + helper.GenerateRandomString(5) projectId, err = helper.CreateTestProject(t, projectName) if err != nil { t.Error(err) diff --git a/test/e2e/ipstest/ips_get_test.go b/test/e2e/ipstest/ips_get_test.go index acf186cc..8a1fc173 100644 --- a/test/e2e/ipstest/ips_get_test.go +++ b/test/e2e/ipstest/ips_get_test.go @@ -43,7 +43,7 @@ func TestCli_Ips_Get(t *testing.T) { t.Skip("Skipping this test because someCondition is true") } root := c.Root() - projectName := "metal-cli-ips-get" + helper.GenerateRandomString(5) + projectName := "metal-cli-ips-get-" + helper.GenerateRandomString(5) projectId, err = helper.CreateTestProject(t, projectName) if err != nil { t.Error(err) diff --git a/test/e2e/ipstest/ips_request_test.go b/test/e2e/ipstest/ips_request_test.go index a7bb6ee9..ae5b9c7a 100644 --- a/test/e2e/ipstest/ips_request_test.go +++ b/test/e2e/ipstest/ips_request_test.go @@ -44,7 +44,7 @@ func TestCli_Vlan_Create(t *testing.T) { t.Skip("Skipping temporarily for now") } root := c.Root() - projectName := "metal-cli-ips-get" + helper.GenerateRandomString(5) + projectName := "metal-cli-ips-get-" + helper.GenerateRandomString(5) projectId, err = helper.CreateTestProject(t, projectName) if err != nil { t.Error(err) diff --git a/test/e2e/vlan/vlan_creat_test.go b/test/e2e/vlan/vlan_creat_test.go index eca53d18..87273d98 100644 --- a/test/e2e/vlan/vlan_creat_test.go +++ b/test/e2e/vlan/vlan_creat_test.go @@ -40,7 +40,7 @@ func TestCli_Vlan_Create(t *testing.T) { want: &cobra.Command{}, cmdFunc: func(t *testing.T, c *cobra.Command) { root := c.Root() - projectName := "metal-cli-vlan-create-pro" + helper.GenerateRandomString(5) + projectName := "metal-cli-vlan-create-pro-" + helper.GenerateRandomString(5) projectId, err = helper.CreateTestProject(t, projectName) if err != nil { t.Error(err) diff --git a/test/e2e/vlan/vlan_delete_test.go b/test/e2e/vlan/vlan_delete_test.go index 5aa5dd68..44904e85 100644 --- a/test/e2e/vlan/vlan_delete_test.go +++ b/test/e2e/vlan/vlan_delete_test.go @@ -40,7 +40,7 @@ func TestCli_Vlan_Clean(t *testing.T) { want: &cobra.Command{}, cmdFunc: func(t *testing.T, c *cobra.Command) { root := c.Root() - projectName := "metal-cli-vlan-get-pro" + helper.GenerateRandomString(5) + projectName := "metal-cli-vlan-get-pro-" + helper.GenerateRandomString(5) projectId, err = helper.CreateTestProject(t, projectName) if err != nil { t.Error(err) diff --git a/test/e2e/vlan/vlan_get_test.go b/test/e2e/vlan/vlan_get_test.go index 296e447b..9c26d9ba 100644 --- a/test/e2e/vlan/vlan_get_test.go +++ b/test/e2e/vlan/vlan_get_test.go @@ -40,7 +40,7 @@ func TestCli_Vlan_Get(t *testing.T) { want: &cobra.Command{}, cmdFunc: func(t *testing.T, c *cobra.Command) { root := c.Root() - projectName := "metal-cli-vlan-delete-pro" + helper.GenerateRandomString(5) + projectName := "metal-cli-vlan-delete-pro-" + helper.GenerateRandomString(5) projectId, err = helper.CreateTestProject(t, projectName) if err != nil { t.Error(err) diff --git a/test/helper/helper.go b/test/helper/helper.go index d5363190..00b5044e 100644 --- a/test/helper/helper.go +++ b/test/helper/helper.go @@ -42,7 +42,7 @@ func CreateTestDevice(t *testing.T, projectId, name string) (string, error) { hostname := name metroDeviceRequest := openapiclient.CreateDeviceRequest{ DeviceCreateInMetroInput: &openapiclient.DeviceCreateInMetroInput{ - Metro: "sv", + Metro: "da", Plan: "m3.small.x86", OperatingSystem: "ubuntu_20_04", Hostname: &hostname,