From b5cdd2511dc73a53211608de4d17de9bce550d7b Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 30 Oct 2024 17:58:00 +0100 Subject: [PATCH] refactor. --- cmd/private_network_create.go | 33 ++++++--------------------------- cmd/private_network_delete.go | 7 +------ cmd/private_network_update.go | 2 +- 3 files changed, 8 insertions(+), 34 deletions(-) diff --git a/cmd/private_network_create.go b/cmd/private_network_create.go index 15718506..abc7e436 100644 --- a/cmd/private_network_create.go +++ b/cmd/private_network_create.go @@ -9,7 +9,6 @@ import ( "github.com/exoscale/cli/pkg/globalstate" "github.com/exoscale/cli/pkg/output" - "github.com/exoscale/cli/utils" v3 "github.com/exoscale/egoscale/v3" ) @@ -57,31 +56,11 @@ func (c *privateNetworkCreateCmd) cmdRun(_ *cobra.Command, _ []string) error { } req := v3.CreatePrivateNetworkRequest{ - Description: func() string { - if c.Description != "" { - return *utils.NonEmptyStringPtr(c.Description) - } - return "" - }(), - EndIP: func() net.IP { - if c.EndIP != "" { - return net.ParseIP(c.EndIP) - } - return nil - }(), - Name: c.Name, - Netmask: func() net.IP { - if c.Netmask != "" { - return net.ParseIP(c.Netmask) - } - return nil - }(), - StartIP: func() net.IP { - if c.StartIP != "" { - return net.ParseIP(c.StartIP) - } - return nil - }(), + Name: c.Name, + Description: c.Description, + EndIP: net.ParseIP(c.EndIP), + Netmask: net.ParseIP(c.Netmask), + StartIP: net.ParseIP(c.StartIP), } opts := &v3.PrivateNetworkOptions{} @@ -138,7 +117,7 @@ func (c *privateNetworkCreateCmd) cmdRun(_ *cobra.Command, _ []string) error { return (&privateNetworkShowCmd{ cliCommandSettings: c.cliCommandSettings, PrivateNetwork: op.Reference.ID.String(), - Zone: v3.ZoneName(c.Zone), + Zone: c.Zone, }).cmdRun(nil, nil) } diff --git a/cmd/private_network_delete.go b/cmd/private_network_delete.go index a407f0e0..276d8b57 100644 --- a/cmd/private_network_delete.go +++ b/cmd/private_network_delete.go @@ -50,18 +50,13 @@ func (c *privateNetworkDeleteCmd) cmdRun(_ *cobra.Command, _ []string) error { return err } - privateNetwork, err := client.GetPrivateNetwork(ctx, pn.ID) - if err != nil { - return err - } - if !c.Force { if !askQuestion(fmt.Sprintf("Are you sure you want to delete Private Network %s?", c.PrivateNetwork)) { return nil } } - op, err := client.DeletePrivateNetwork(ctx, privateNetwork.ID) + op, err := client.DeletePrivateNetwork(ctx, pn.ID) if err != nil { return err } diff --git a/cmd/private_network_update.go b/cmd/private_network_update.go index dc91054b..2011a667 100644 --- a/cmd/private_network_update.go +++ b/cmd/private_network_update.go @@ -156,7 +156,7 @@ func (c *privateNetworkUpdateCmd) cmdRun(cmd *cobra.Command, _ []string) error { return (&privateNetworkShowCmd{ cliCommandSettings: c.cliCommandSettings, PrivateNetwork: privnetID.String(), - Zone: v3.ZoneName(c.Zone), + Zone: c.Zone, }).cmdRun(nil, nil) }