fix(deploy-key): require a key ID for delete
What does this MR do and why?
glab deploy-key delete treats its key ID as required everywhere except in
argument validation:
Use: "delete <key-id>",
Long: `Pass the ID of the key to delete as an argument. ...
This action is permanent and cannot be undone.`,
Example: `glab deploy-key delete 1234`,
Args: cobra.MaximumNArgs(1),MaximumNArgs(1) also accepts zero arguments, and complete only assigns
keyID when exactly one is present:
if len(args) == 1 {
...
o.keyID = int64(strInt)
}So running the command with no argument leaves keyID at zero and sends
DELETE /projects/:id/deploy_keys/0, then prints "Deploy key deleted." The
command carries the Destructive MCP annotation, so it should not reach the
API with an ID the user never supplied. There is no interactive fallback that
would justify the optional argument.
cobra.ExactArgs(1) makes validation agree with the documented contract, and
the new test case covers the no-argument path.
How to reproduce
glab deploy-key delete --repo group/project
# DELETE /api/v4/projects/group%2Fproject/deploy_keys/0
# Deploy key deleted.
# exit 0Test coverage
Test_DeployKeyRemove gains a "Remove a deploy key without a key ID" case
that asserts the argument error and registers no mock call, so a regression
that reaches the API would fail the expectation.
Related issues
Closes #8410