Skip to content

Commit

Permalink
fix: "device update --lock" should also unlock
Browse files Browse the repository at this point in the history
Signed-off-by: Marques Johansson <mjohansson@equinix.com>
  • Loading branch information
displague committed Aug 26, 2024
1 parent b5eaed2 commit 34ccdcd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion docs/metal_device_update.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ metal device update -i <device_id> [-H <hostname>] [-d <description>] [--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 (<true|false>).
-l, --locked bools Locks or unlocks the device for future changes (<true|false>). (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.
Expand Down
15 changes: 10 additions & 5 deletions internal/devices/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import (
func (c *Client) Update() *cobra.Command {
var (
description string
locked bool
userdata string
userdataFile string
hostname string
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 (<true|false>).")
updateDeviceCmd.Flags().BoolSliceP("locked", "l", []bool{}, "Locks or unlocks the device for future changes (<true|false>).")
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 (<true|false>).")
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
}

0 comments on commit 34ccdcd

Please sign in to comment.