Skip to content

Commit

Permalink
refactor.
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed Oct 30, 2024
1 parent 57aa7c6 commit b5cdd25
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 34 deletions.
33 changes: 6 additions & 27 deletions cmd/private_network_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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{}
Expand Down Expand Up @@ -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)
}

Expand Down
7 changes: 1 addition & 6 deletions cmd/private_network_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/private_network_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down

0 comments on commit b5cdd25

Please sign in to comment.