From 925f0b5222dddf4e7c2a410645e9d5ccaac62f6c Mon Sep 17 00:00:00 2001 From: codinja1188 <3358152+vasubabu@users.noreply.github.com> Date: Wed, 13 Dec 2023 20:27:40 +0530 Subject: [PATCH] fix: Eliminate the obsolete PromptUI library from the project. --- docs/metal_device_delete.md | 2 +- docs/metal_gateway_delete.md | 2 +- docs/metal_organization_delete.md | 2 +- docs/metal_project_delete.md | 2 +- docs/metal_ssh-key_delete.md | 2 +- docs/metal_virtual-network_delete.md | 2 +- docs/metal_vrf_delete.md | 2 +- go.mod | 2 -- go.sum | 10 ------ internal/devices/delete.go | 49 +++++++++++----------------- internal/gateway/delete.go | 25 ++++++++------ internal/organizations/delete.go | 22 ++++++++----- internal/ports/convert.go | 30 ++++++++++++----- internal/projects/delete.go | 26 +++++++++------ internal/ssh/delete.go | 26 +++++++++------ internal/vlan/delete.go | 23 ++++++++----- internal/vrf/delete.go | 23 ++++++++----- 17 files changed, 136 insertions(+), 114 deletions(-) diff --git a/docs/metal_device_delete.md b/docs/metal_device_delete.md index a42005e2..e6d7ca5b 100644 --- a/docs/metal_device_delete.md +++ b/docs/metal_device_delete.md @@ -16,7 +16,7 @@ metal device delete -i [-f] [flags] # Deletes the specified device: metal device delete -i 7ec86e23-8dcf-48ed-bd9b-c25c20958277 > - ✔ Are you sure you want to delete device 7ec86e23-8dcf-48ed-bd9b-c25c20958277: y + ✔ Are you sure you want to delete device 7ec86e23-8dcf-48ed-bd9b-c25c20958277 [Y/N]: y # Deletes a VLAN, skipping confirmation: metal device delete -f -i 7ec86e23-8dcf-48ed-bd9b-c25c20958277 diff --git a/docs/metal_gateway_delete.md b/docs/metal_gateway_delete.md index f36a38f0..ba8a2ce5 100644 --- a/docs/metal_gateway_delete.md +++ b/docs/metal_gateway_delete.md @@ -16,7 +16,7 @@ metal gateway delete -i [-f] [flags] # Deletes a Gateway, with confirmation. metal gateway delete -i 77e6d57a-d7a4-4816-b451-cf9b043444e2 > - ✔ Are you sure you want to delete Metal Gateway 77e6d57a-d7a4-4816-b451-cf9b043444e2: y + ✔ Are you sure you want to delete Metal Gateway 77e6d57a-d7a4-4816-b451-cf9b043444e2 [Y/N]: y # Deletes a Gateway, skipping confirmation. metal gateway delete -f -i 77e6d57a-d7a4-4816-b451-cf9b043444e2 diff --git a/docs/metal_organization_delete.md b/docs/metal_organization_delete.md index 42fdb01a..7cdcb6fa 100644 --- a/docs/metal_organization_delete.md +++ b/docs/metal_organization_delete.md @@ -16,7 +16,7 @@ metal organization delete -i [flags] # Deletes an organization, with confirmation: metal organization delete -i 3bd5bf07-6094-48ad-bd03-d94e8712fdc8 > - ✔ Are you sure you want to delete organization 3bd5bf07-6094-48ad-bd03-d94e8712fdc8: y + ✔ Are you sure you want to delete organization 3bd5bf07-6094-48ad-bd03-d94e8712fdc8 [Y/N]: y # Deletes an organization, skipping confirmation: metal organization delete -i 3bd5bf07-6094-48ad-bd03-d94e8712fdc8 -f diff --git a/docs/metal_project_delete.md b/docs/metal_project_delete.md index 7ad2b4b5..c69f43a1 100644 --- a/docs/metal_project_delete.md +++ b/docs/metal_project_delete.md @@ -16,7 +16,7 @@ metal project delete --id [--force] [flags] # Deletes project 50693ba9-e4e4-4d8a-9eb2-4840b11e9375: metal project delete -i 50693ba9-e4e4-4d8a-9eb2-4840b11e9375 > - ✔ Are you sure you want to delete project 50693ba9-e4e4-4d8a-9eb2-4840b11e9375: y + ✔ Are you sure you want to delete project 50693ba9-e4e4-4d8a-9eb2-4840b11e9375 [Y/N]: y # Deletes project 50693ba9-e4e4-4d8a-9eb2-4840b11e9375, skipping confirmation: metal project delete -i 50693ba9-e4e4-4d8a-9eb2-4840b11e9375 -f diff --git a/docs/metal_ssh-key_delete.md b/docs/metal_ssh-key_delete.md index fc75d6b9..97e1b76b 100644 --- a/docs/metal_ssh-key_delete.md +++ b/docs/metal_ssh-key_delete.md @@ -16,7 +16,7 @@ metal ssh-key delete --id [--force] [flags] # Deletes an SSH key, with confirmation: metal ssh-key delete -i 5cb96463-88fd-4d68-94ba-2c9505ff265e > - ✔ Are you sure you want to delete SSH Key 5cb96463-88fd-4d68-94ba-2c9505ff265e: y + ✔ Are you sure you want to delete SSH Key 5cb96463-88fd-4d68-94ba-2c9505ff265e [Y/N]: y # Deletes an SSH key, skipping confirmation: metal ssh-key delete -i 5cb96463-88fd-4d68-94ba-2c9505ff265e -f diff --git a/docs/metal_virtual-network_delete.md b/docs/metal_virtual-network_delete.md index 914f153f..41a9267d 100644 --- a/docs/metal_virtual-network_delete.md +++ b/docs/metal_virtual-network_delete.md @@ -16,7 +16,7 @@ metal virtual-network delete -i [-f] [flags] # Deletes a VLAN, with confirmation. metal virtual-network delete -i 77e6d57a-d7a4-4816-b451-cf9b043444e2 > - ✔ Are you sure you want to delete virtual network 77e6d57a-d7a4-4816-b451-cf9b043444e2: y + ✔ Are you sure you want to delete virtual network 77e6d57a-d7a4-4816-b451-cf9b043444e2 [Y/N]: y # Deletes a VLAN, skipping confirmation. metal virtual-network delete -f -i 77e6d57a-d7a4-4816-b451-cf9b043444e2 diff --git a/docs/metal_vrf_delete.md b/docs/metal_vrf_delete.md index 743eabe3..4ff3c618 100644 --- a/docs/metal_vrf_delete.md +++ b/docs/metal_vrf_delete.md @@ -16,7 +16,7 @@ metal vrf delete vrf -i [-f] [flags] # Deletes a VRF, with confirmation. metal delete vrf -i 77e6d57a-d7a4-4816-b451-cf9b043444e2 > - ✔ Are you sure you want to delete device 7ec86e23-8dcf-48ed-bd9b-c25c20958277: y + ✔ Are you sure you want to delete device 7ec86e23-8dcf-48ed-bd9b-c25c20958277 [Y/N]: y # Deletes a VRF, skipping confirmation. metal delete vrf -f -i 77e6d57a-d7a4-4816-b451-cf9b043444e2 diff --git a/go.mod b/go.mod index 08def837..44acb1b3 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,6 @@ go 1.19 require ( github.com/equinix-labs/metal-go v0.26.0 - github.com/manifoldco/promptui v0.9.0 github.com/olekukonko/tablewriter v0.0.5 github.com/packethost/packngo v0.30.0 github.com/pkg/errors v0.9.1 @@ -17,7 +16,6 @@ require ( ) require ( - github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e // indirect github.com/cpuguy83/go-md2man/v2 v2.0.3 // indirect github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect github.com/fsnotify/fsnotify v1.6.0 // indirect diff --git a/go.sum b/go.sum index 77c7f9bb..8ca66f17 100644 --- a/go.sum +++ b/go.sum @@ -39,11 +39,8 @@ dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7 github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= -github.com/chzyer/logex v1.1.10 h1:Swpa1K6QvQznwJRcfTfQJmTE72DqScAa40E+fbHEXEE= github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= -github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e h1:fY5BOSpyZCqRo5OhCuC+XN+r/bBCmeuuJtjz+bCNIf8= github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= -github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1 h1:q763qf9huN11kDQavWsoZXJNW3xEE4JJyHa5Q25/sd8= github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= @@ -146,8 +143,6 @@ github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY= github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= -github.com/manifoldco/promptui v0.9.0 h1:3V4HzJk1TtXW1MTZMP7mdlwbBpIinw3HztaIlYthEiA= -github.com/manifoldco/promptui v0.9.0/go.mod h1:ka04sppxSGFAtxX0qhlYQjISsg9mR4GWtQEhdbn6Pgg= github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0= github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= @@ -310,7 +305,6 @@ golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -346,13 +340,9 @@ golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q= -golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc= golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/term v0.14.0 h1:LGK9IlZ8T9jvdy6cTdfKUCltatMFOehAQo9SRC46UQ8= -golang.org/x/term v0.14.0/go.mod h1:TySc+nGkYR6qt8km8wUhuFRTVSMIX3XPR58y2lC8vww= golang.org/x/term v0.15.0 h1:y/Oo/a/q3IXu26lQgl04j/gjuBDOBlx7X6Om1j2CPW4= golang.org/x/term v0.15.0/go.mod h1:BDl952bC7+uMoWR75FIrCDx79TPU9oHkTZ9yRbYOrX0= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= diff --git a/internal/devices/delete.go b/internal/devices/delete.go index 1ca13632..35575f12 100644 --- a/internal/devices/delete.go +++ b/internal/devices/delete.go @@ -1,36 +1,19 @@ -// Copyright © 2018 Jasmin Gacic -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - package devices import ( "context" "fmt" + "strings" - "github.com/manifoldco/promptui" "github.com/spf13/cobra" ) func (c *Client) Delete() *cobra.Command { - var deviceID string - var force bool + var ( + deviceID string + force bool + confirmation string + ) deleteDevice := func(id string) error { _, err := c.Service.DeleteDevice(context.Background(), id).ForceDelete(force).Execute() if err != nil { @@ -46,26 +29,32 @@ func (c *Client) Delete() *cobra.Command { Example: ` # Deletes the specified device: metal device delete -i 7ec86e23-8dcf-48ed-bd9b-c25c20958277 > - ✔ Are you sure you want to delete device 7ec86e23-8dcf-48ed-bd9b-c25c20958277: y + ✔ Are you sure you want to delete device 7ec86e23-8dcf-48ed-bd9b-c25c20958277 [Y/N]: y # Deletes a VLAN, skipping confirmation: metal device delete -f -i 7ec86e23-8dcf-48ed-bd9b-c25c20958277`, RunE: func(cmd *cobra.Command, args []string) error { cmd.SilenceUsage = true + if !force { - prompt := promptui.Prompt{ - Label: fmt.Sprintf("Are you sure you want to delete device %s: ", deviceID), - IsConfirm: true, - } + fmt.Printf("Are you sure you want to delete device %s [Y/N]: ", deviceID) - _, err := prompt.Run() + _, 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("Device deletion cancelled.") return nil } } + if err := deleteDevice(deviceID); err != nil { - return fmt.Errorf("Could not delete Device: %w", err) + return fmt.Errorf("could not delete Device: %w", err) } return nil }, diff --git a/internal/gateway/delete.go b/internal/gateway/delete.go index 6d5bd7a3..0fd5175f 100644 --- a/internal/gateway/delete.go +++ b/internal/gateway/delete.go @@ -23,15 +23,16 @@ package gateway import ( "context" "fmt" + "strings" - "github.com/manifoldco/promptui" "github.com/spf13/cobra" ) func (c *Client) Delete() *cobra.Command { var ( - gwayID string - force bool + gwayID string + force bool + confirmation string ) includes := []string{"virtual_network", "ip_reservation"} @@ -56,7 +57,7 @@ func (c *Client) Delete() *cobra.Command { Example: ` # Deletes a Gateway, with confirmation. metal gateway delete -i 77e6d57a-d7a4-4816-b451-cf9b043444e2 > - ✔ Are you sure you want to delete Metal Gateway 77e6d57a-d7a4-4816-b451-cf9b043444e2: y + ✔ Are you sure you want to delete Metal Gateway 77e6d57a-d7a4-4816-b451-cf9b043444e2 [Y/N]: y # Deletes a Gateway, skipping confirmation. metal gateway delete -f -i 77e6d57a-d7a4-4816-b451-cf9b043444e2`, @@ -65,18 +66,22 @@ func (c *Client) Delete() *cobra.Command { cmd.SilenceUsage = true if !force { - prompt := promptui.Prompt{ - Label: fmt.Sprintf("Are you sure you want to delete Metal Gateway %s", gwayID), - IsConfirm: true, - } + fmt.Printf("Are you sure you want to delete Metal Gateway %s [Y/N]: ", gwayID) - _, err := prompt.Run() + _, 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("Metal Gateway deletion cancelled.") return nil } } if err := deleteGway(gwayID); err != nil { - return fmt.Errorf("Could not delete Metal Gateway: %w", err) + return fmt.Errorf("could not delete Metal Gateway: %w", err) } return nil }, diff --git a/internal/organizations/delete.go b/internal/organizations/delete.go index aef4e3bd..7a006200 100644 --- a/internal/organizations/delete.go +++ b/internal/organizations/delete.go @@ -23,8 +23,8 @@ package organizations import ( "context" "fmt" + "strings" - "github.com/manifoldco/promptui" "github.com/spf13/cobra" ) @@ -32,6 +32,7 @@ func (c *Client) Delete() *cobra.Command { var ( organizationID string force bool + confirmation string ) deleteOrganization := func(id string) error { _, err := c.Service.DeleteOrganization(context.Background(), id).Execute() @@ -51,26 +52,31 @@ func (c *Client) Delete() *cobra.Command { Example: ` # Deletes an organization, with confirmation: metal organization delete -i 3bd5bf07-6094-48ad-bd03-d94e8712fdc8 > - ✔ Are you sure you want to delete organization 3bd5bf07-6094-48ad-bd03-d94e8712fdc8: y + ✔ Are you sure you want to delete organization 3bd5bf07-6094-48ad-bd03-d94e8712fdc8 [Y/N]: y # Deletes an organization, skipping confirmation: metal organization delete -i 3bd5bf07-6094-48ad-bd03-d94e8712fdc8 -f`, RunE: func(cmd *cobra.Command, args []string) error { cmd.SilenceUsage = true + if !force { - prompt := promptui.Prompt{ - Label: fmt.Sprintf("Are you sure you want to delete organization %s: ", organizationID), - IsConfirm: true, - } + fmt.Printf("Are you sure you want to delete organization %s [Y/N]: ", organizationID) - _, err := prompt.Run() + _, 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("organization deletion cancelled.") return nil } } if err := deleteOrganization(organizationID); err != nil { - return fmt.Errorf("Could not delete Organization: %w", err) + return fmt.Errorf("could not delete Organization: %w", err) } return nil }, diff --git a/internal/ports/convert.go b/internal/ports/convert.go index ade72812..6d4b2330 100644 --- a/internal/ports/convert.go +++ b/internal/ports/convert.go @@ -26,15 +26,23 @@ import ( "log" "net/http" "strconv" + "strings" metal "github.com/equinix-labs/metal-go/metal/v1" - "github.com/manifoldco/promptui" "github.com/spf13/cobra" ) func (c *Client) Convert() *cobra.Command { - var portID string - var bonded, layer2, bulk, force, ipv4, ipv6 bool + var ( + portID string + bonded bool + layer2 bool + bulk bool + force bool + ipv4 bool + ipv6 bool + confirmation string + ) convertPortCmd := &cobra.Command{ Use: `convert -i [--bonded] [--bulk] --layer2 [--force] [--public-ipv4] [--public-ipv6]`, Aliases: []string{}, @@ -62,18 +70,22 @@ func (c *Client) Convert() *cobra.Command { } convToL2 := func(portID string) (*metal.Port, *http.Response, error) { + if !force { - prompt := promptui.Prompt{ - Label: fmt.Sprintf("Are you sure you want to convert Port %s to Layer2 and remove assigned IP addresses: ", portID), - IsConfirm: true, - } + fmt.Printf("Are you sure you want to convert Port %s to Layer2 and remove assigned IP addresses [Y/N]: ", portID) - _, err := prompt.Run() + _, err := fmt.Scanln(&confirmation) if err != nil { + fmt.Println("Error reading confirmation:", err) return nil, nil, nil } - } + confirmation = strings.TrimSpace(strings.ToLower(confirmation)) + if confirmation != "yes" && confirmation != "y" { + fmt.Println("convert Port to Layer2 cancelled.") + return nil, nil, nil + } + } return c.PortService.ConvertLayer2(context.Background(), portID). PortAssignInput(*metal.NewPortAssignInput()). Execute() diff --git a/internal/projects/delete.go b/internal/projects/delete.go index f05c90de..fe85b8ad 100644 --- a/internal/projects/delete.go +++ b/internal/projects/delete.go @@ -23,15 +23,16 @@ package projects import ( "context" "fmt" + "strings" - "github.com/manifoldco/promptui" "github.com/spf13/cobra" ) func (c *Client) Delete() *cobra.Command { var ( - force bool - projectID string + force bool + projectID string + confirmation string ) deleteProject := func(id string) error { _, err := c.ProjectService.DeleteProject(context.Background(), id).Execute() @@ -49,26 +50,31 @@ func (c *Client) Delete() *cobra.Command { Example: ` # Deletes project 50693ba9-e4e4-4d8a-9eb2-4840b11e9375: metal project delete -i 50693ba9-e4e4-4d8a-9eb2-4840b11e9375 > - ✔ Are you sure you want to delete project 50693ba9-e4e4-4d8a-9eb2-4840b11e9375: y + ✔ Are you sure you want to delete project 50693ba9-e4e4-4d8a-9eb2-4840b11e9375 [Y/N]: y # Deletes project 50693ba9-e4e4-4d8a-9eb2-4840b11e9375, skipping confirmation: metal project delete -i 50693ba9-e4e4-4d8a-9eb2-4840b11e9375 -f`, RunE: func(cmd *cobra.Command, args []string) error { cmd.SilenceUsage = true + if !force { - prompt := promptui.Prompt{ - Label: fmt.Sprintf("Are you sure you want to delete project %s: ", projectID), - IsConfirm: true, - } + fmt.Printf("Are you sure you want to delete project %s [Y/N]: ", projectID) - _, err := prompt.Run() + _, 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("project deletion cancelled.") return nil } } if err := deleteProject(projectID); err != nil { - return fmt.Errorf("Could not delete Project: %w", err) + return fmt.Errorf("could not delete Project: %w", err) } return nil }, diff --git a/internal/ssh/delete.go b/internal/ssh/delete.go index f19de5aa..c368dae7 100644 --- a/internal/ssh/delete.go +++ b/internal/ssh/delete.go @@ -23,15 +23,16 @@ package ssh import ( "context" "fmt" + "strings" - "github.com/manifoldco/promptui" "github.com/spf13/cobra" ) func (c *Client) Delete() *cobra.Command { var ( - sshKeyID string - force bool + sshKeyID string + force bool + confirmation string ) deleteSSHKey := func(id string) error { _, err := c.Service.DeleteSSHKey(context.Background(), sshKeyID).Execute() @@ -49,27 +50,32 @@ func (c *Client) Delete() *cobra.Command { Example: ` # Deletes an SSH key, with confirmation: metal ssh-key delete -i 5cb96463-88fd-4d68-94ba-2c9505ff265e > - ✔ Are you sure you want to delete SSH Key 5cb96463-88fd-4d68-94ba-2c9505ff265e: y + ✔ Are you sure you want to delete SSH Key 5cb96463-88fd-4d68-94ba-2c9505ff265e [Y/N]: y # Deletes an SSH key, skipping confirmation: metal ssh-key delete -i 5cb96463-88fd-4d68-94ba-2c9505ff265e -f`, RunE: func(cmd *cobra.Command, args []string) error { cmd.SilenceUsage = true + if !force { - prompt := promptui.Prompt{ - Label: fmt.Sprintf("Are you sure you want to delete SSH Key %s: ", sshKeyID), - IsConfirm: true, - } + fmt.Printf("Are you sure you want to delete SSH Key %s [Y/N]: ", sshKeyID) - _, err := prompt.Run() + _, 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("SSH Key deletion cancelled.") return nil } } if err := deleteSSHKey(sshKeyID); err != nil { - return fmt.Errorf("Could not delete SSH Key: %w", err) + return fmt.Errorf("could not delete SSH Key: %w", err) } return nil }, diff --git a/internal/vlan/delete.go b/internal/vlan/delete.go index e975a6ea..2551332a 100644 --- a/internal/vlan/delete.go +++ b/internal/vlan/delete.go @@ -23,15 +23,16 @@ package vlan import ( "context" "fmt" + "strings" - "github.com/manifoldco/promptui" "github.com/spf13/cobra" ) func (c *Client) Delete() *cobra.Command { var ( - vnetID string - force bool + vnetID string + force bool + confirmation string ) deleteVnet := func(id string) error { @@ -51,7 +52,7 @@ func (c *Client) Delete() *cobra.Command { Example: ` # Deletes a VLAN, with confirmation. metal virtual-network delete -i 77e6d57a-d7a4-4816-b451-cf9b043444e2 > - ✔ Are you sure you want to delete virtual network 77e6d57a-d7a4-4816-b451-cf9b043444e2: y + ✔ Are you sure you want to delete virtual network 77e6d57a-d7a4-4816-b451-cf9b043444e2 [Y/N]: y # Deletes a VLAN, skipping confirmation. metal virtual-network delete -f -i 77e6d57a-d7a4-4816-b451-cf9b043444e2`, @@ -60,13 +61,17 @@ func (c *Client) Delete() *cobra.Command { cmd.SilenceUsage = true if !force { - prompt := promptui.Prompt{ - Label: fmt.Sprintf("Are you sure you want to delete virtual network %s", vnetID), - IsConfirm: true, - } + fmt.Printf("Are you sure you want to delete virtual network %s [Y/N]: ", vnetID) - _, err := prompt.Run() + _, 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("virtual network deletion cancelled.") return nil } } diff --git a/internal/vrf/delete.go b/internal/vrf/delete.go index 9d39eb45..c1d3db87 100644 --- a/internal/vrf/delete.go +++ b/internal/vrf/delete.go @@ -3,15 +3,16 @@ package vrf import ( "context" "fmt" + "strings" - "github.com/manifoldco/promptui" "github.com/spf13/cobra" ) func (c *Client) Delete() *cobra.Command { var ( - vrfID string - force bool + vrfID string + force bool + confirmation string ) deleteVrf := func(id string) error { @@ -31,7 +32,7 @@ func (c *Client) Delete() *cobra.Command { Example: `# Deletes a VRF, with confirmation. metal delete vrf -i 77e6d57a-d7a4-4816-b451-cf9b043444e2 > - ✔ Are you sure you want to delete device 7ec86e23-8dcf-48ed-bd9b-c25c20958277: y + ✔ Are you sure you want to delete device 7ec86e23-8dcf-48ed-bd9b-c25c20958277 [Y/N]: y # Deletes a VRF, skipping confirmation. metal delete vrf -f -i 77e6d57a-d7a4-4816-b451-cf9b043444e2`, @@ -39,13 +40,17 @@ func (c *Client) Delete() *cobra.Command { cmd.SilenceUsage = true if !force { - prompt := promptui.Prompt{ - Label: fmt.Sprintf("Are you sure you want to delete VRF %s: ", vrfID), - IsConfirm: true, + fmt.Printf("Are you sure you want to delete VRF %s [Y/N]: ", vrfID) + + _, err := fmt.Scanln(&confirmation) + if err != nil { + fmt.Println("Error reading confirmation:", err) + return nil } - result, err := prompt.Run() - if err != nil || result != "y" { + confirmation = strings.TrimSpace(strings.ToLower(confirmation)) + if confirmation != "yes" && confirmation != "y" { + fmt.Println("VRF deletion cancelled.") return nil } }