metal-cli icon indicating copy to clipboard operation
metal-cli copied to clipboard

fix: "device update --locked" should also unlock

Open displague opened this issue 5 months ago • 2 comments

Fixes #484

Previous behavior was to set {"locked":true} in PUT requests whenever --locked was specified. This is because the presence of the flag itself is treated as a toggle. The value argument was ignored unless given as --locked=true or --locked=false. When --locked=false was given, the PUT request was {}, since the code required true values to add the field to the update request.

This change technically breaks the current ability to do metal device update --locked --some-other-arg.

$ PACKNGO_DEBUG=1 go run ./cmd/metal device update --locked false --locked true --id 1234
Error: parameter locked may only be set once
$ PACKNGO_DEBUG=1 go run ./cmd/metal device update --locked --id 1234                    
Error: invalid argument "--id" for "-l, --locked" flag: strconv.ParseBool: parsing "--id": invalid syntax
...
$ PACKNGO_DEBUG=1 go run ./cmd/metal device update --locked true  --id 1234              
PUT /metal/v1//devices/1234 HTTP/1.1
...
{"locked":true}
$ PACKNGO_DEBUG=1 go run ./cmd/metal device update --locked false  --id 1234
PUT /metal/v1//devices/1234 HTTP/1.1
...
{"locked":false}

displague avatar Aug 26 '24 18:08 displague