Skip to content

Commit

Permalink
fix: removing the obsolete PromptUI library from the project. (#407)
Browse files Browse the repository at this point in the history
## What fixes the PR?

#331
  • Loading branch information
displague committed Dec 14, 2023
2 parents fdd1499 + 925f0b5 commit d82cb24
Show file tree
Hide file tree
Showing 17 changed files with 136 additions and 114 deletions.
2 changes: 1 addition & 1 deletion docs/metal_device_delete.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ metal device delete -i <device_id> [-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
Expand Down
2 changes: 1 addition & 1 deletion docs/metal_gateway_delete.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ metal gateway delete -i <metal_gateway_UUID> [-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
Expand Down
2 changes: 1 addition & 1 deletion docs/metal_organization_delete.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ metal organization delete -i <organization_UUID> [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
Expand Down
2 changes: 1 addition & 1 deletion docs/metal_project_delete.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ metal project delete --id <project_UUID> [--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
Expand Down
2 changes: 1 addition & 1 deletion docs/metal_ssh-key_delete.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ metal ssh-key delete --id <SSH-key_UUID> [--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
Expand Down
2 changes: 1 addition & 1 deletion docs/metal_virtual-network_delete.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ metal virtual-network delete -i <virtual_network_UUID> [-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
Expand Down
2 changes: 1 addition & 1 deletion docs/metal_vrf_delete.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ metal vrf delete vrf -i <metal_vrf_UUID> [-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
Expand Down
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
10 changes: 0 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down
49 changes: 19 additions & 30 deletions internal/devices/delete.go
Original file line number Diff line number Diff line change
@@ -1,36 +1,19 @@
// Copyright © 2018 Jasmin Gacic <jasmin@stackpointcloud.com>
//
// 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 {
Expand All @@ -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
},
Expand Down
25 changes: 15 additions & 10 deletions internal/gateway/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"}

Expand All @@ -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`,
Expand All @@ -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
},
Expand Down
22 changes: 14 additions & 8 deletions internal/organizations/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,16 @@ package organizations
import (
"context"
"fmt"
"strings"

"github.com/manifoldco/promptui"
"github.com/spf13/cobra"
)

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()
Expand All @@ -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
},
Expand Down
30 changes: 21 additions & 9 deletions internal/ports/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 <port_UUID> [--bonded] [--bulk] --layer2 [--force] [--public-ipv4] [--public-ipv6]`,
Aliases: []string{},
Expand Down Expand Up @@ -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()
Expand Down
Loading

0 comments on commit d82cb24

Please sign in to comment.