From 5758db62a423164cc305d71b32fde6b7b8adf286 Mon Sep 17 00:00:00 2001 From: elkezza <47871727+elkezza@users.noreply.github.com> Date: Fri, 9 Aug 2024 16:08:57 +0200 Subject: [PATCH] new update in the instance_update.go --- cmd/instance_create.go | 4 +++- cmd/instance_update.go | 32 ++++++++++++++++++-------------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/cmd/instance_create.go b/cmd/instance_create.go index 8564b884..3a62e29d 100644 --- a/cmd/instance_create.go +++ b/cmd/instance_create.go @@ -211,8 +211,10 @@ func (c *instanceCreateCmd) cmdRun(_ *cobra.Command, _ []string) error { //nolin return } } + fmt.Printf("Protection flag value: %v\n", c.Protection) if c.Protection { + fmt.Println("Protection flag is set, adding protection...") var value egoscale3.UUID var op *egoscale3.Operation value, err = egoscale3.ParseUUID(*instance.ID) @@ -223,7 +225,7 @@ func (c *instanceCreateCmd) cmdRun(_ *cobra.Command, _ []string) error { //nolin if err != nil { return } - op, err = globalstate.EgoscaleV3Client.Wait(ctx, op, egoscale3.OperationStateSuccess) + _, err = globalstate.EgoscaleV3Client.Wait(ctx, op, egoscale3.OperationStateSuccess) } }) diff --git a/cmd/instance_update.go b/cmd/instance_update.go index b5d131fd..53ec8952 100644 --- a/cmd/instance_update.go +++ b/cmd/instance_update.go @@ -99,21 +99,25 @@ func (c *instanceUpdateCmd) cmdRun(cmd *cobra.Command, _ []string) error { err = globalstate.EgoscaleClient.UpdateInstanceReverseDNS(ctx, c.Zone, *instance.ID, c.ReverseDNS) } } - var value egoscale3.UUID - var op *egoscale3.Operation - value, err = egoscale3.ParseUUID(*instance.ID) - if err != nil { - return - } - if c.Protection { - op, err = globalstate.EgoscaleV3Client.AddInstanceProtection(ctx, value) - } else { - op, err = globalstate.EgoscaleV3Client.RemoveInstanceProtection(ctx, value) - } - if err != nil { - return + + if cmd.Flags().Changed(mustCLICommandFlagName(c, &c.Protection)) { + fmt.Println("Protection flag is set, adding protection...") + var value egoscale3.UUID + var op *egoscale3.Operation + value, err = egoscale3.ParseUUID(*instance.ID) + if err != nil { + return + } + if c.Protection { + op, err = globalstate.EgoscaleV3Client.AddInstanceProtection(ctx, value) + } else { + op, err = globalstate.EgoscaleV3Client.RemoveInstanceProtection(ctx, value) + } + if err != nil { + return + } + _, err = globalstate.EgoscaleV3Client.Wait(ctx, op, egoscale3.OperationStateSuccess) } - op, err = globalstate.EgoscaleV3Client.Wait(ctx, op, egoscale3.OperationStateSuccess) })