From 34ccdcd3aafbc33d21c12420a0af14ecb2f45de1 Mon Sep 17 00:00:00 2001 From: Marques Johansson Date: Mon, 26 Aug 2024 13:57:35 -0400 Subject: [PATCH] fix: "device update --lock" should also unlock Signed-off-by: Marques Johansson --- docs/metal_device_update.md | 2 +- internal/devices/update.go | 15 ++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/docs/metal_device_update.md b/docs/metal_device_update.md index abb7ba3d..0d231f78 100644 --- a/docs/metal_device_update.md +++ b/docs/metal_device_update.md @@ -27,7 +27,7 @@ metal device update -i [-H ] [-d ] [--locked -H, --hostname string The new hostname of the device. -i, --id string The UUID of the device. -s, --ipxe-script-url string Add or update the URL of the iPXE script. - -l, --locked Locks or unlocks the device for future changes (). + -l, --locked bools Locks or unlocks the device for future changes (). (default []) -t, --tags strings Adds or updates the tags for the device --tags="tag1,tag2". -u, --userdata string Adds or updates the userdata for the device. --userdata-file string Path to a userdata file for device initialization. Can not be used with --userdata. diff --git a/internal/devices/update.go b/internal/devices/update.go index b53187c0..23331dd1 100644 --- a/internal/devices/update.go +++ b/internal/devices/update.go @@ -34,7 +34,6 @@ import ( func (c *Client) Update() *cobra.Command { var ( description string - locked bool userdata string userdataFile string hostname string @@ -80,8 +79,15 @@ func (c *Client) Update() *cobra.Command { deviceUpdate.Userdata = &userdata } - if locked { - deviceUpdate.Locked = &locked + if cmd.Flag("locked").Changed { + locked, err := cmd.Flags().GetBoolSlice("locked") + if err != nil { + return fmt.Errorf("could not parse locked value: %w", err) + } + if len(locked) > 1 { + return fmt.Errorf("parameter locked may only be set once") + } + deviceUpdate.Locked = &locked[0] } if len(tags) > 0 { @@ -123,12 +129,11 @@ func (c *Client) Update() *cobra.Command { updateDeviceCmd.Flags().StringVarP(&description, "description", "d", "", "Adds or updates the description for the device.") updateDeviceCmd.Flags().StringVarP(&userdata, "userdata", "u", "", "Adds or updates the userdata for the device.") updateDeviceCmd.Flags().StringVarP(&userdataFile, "userdata-file", "", "", "Path to a userdata file for device initialization. Can not be used with --userdata.") - updateDeviceCmd.Flags().BoolVarP(&locked, "locked", "l", false, "Locks or unlocks the device for future changes ().") + updateDeviceCmd.Flags().BoolSliceP("locked", "l", []bool{}, "Locks or unlocks the device for future changes ().") updateDeviceCmd.Flags().StringSliceVarP(&tags, "tags", "t", []string{}, `Adds or updates the tags for the device --tags="tag1,tag2".`) updateDeviceCmd.Flags().BoolVarP(&alwaysPXE, "always-pxe", "a", false, "Updates the always_pxe toggle for the device ().") updateDeviceCmd.Flags().StringVarP(&ipxescripturl, "ipxe-script-url", "s", "", "Add or update the URL of the iPXE script.") updateDeviceCmd.Flags().StringVarP(&customdata, "customdata", "c", "", "Adds or updates custom data to be included with your device's metadata.") _ = updateDeviceCmd.MarkFlagRequired("id") - return updateDeviceCmd }