Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed extra args in cmds #295

Closed
wants to merge 1 commit into from
Closed

Conversation

Roaster05
Copy link
Contributor

This PR fixes issue #293 and extends its coverage to other commands by ensuring that an error message is sent if any extra arguments are provided to commands that do not require them.

Current behavior:

./harbor-cli label create newLabel
FATA[0000] Error: accepts 0 arg(s), received 1: [newLabel]

./harbor-cli project list extra args
FATA[0000] Error: accepts 0 arg(s), received 2: [extra args]

The fix adds a PreRun step before the command is executed to exit if any arguments are provided.

Signed-off-by: Roaster05 <[email protected]>
@bupd
Copy link
Member

bupd commented Dec 30, 2024

The fix adds a PreRun step before the command is executed to exit if any arguments are provided.

We acutally don't need it. It adds unnecessary complexity

@Roaster05
Copy link
Contributor Author

The fix adds a PreRun step before the command is executed to exit if any arguments are provided.

We acutally don't need it. It adds unnecessary complexity

Yes, we can also just add Args: cobra.NoArgs, in the cmd definition, but this will throw an error like Error: unknown command "newLabel" for "harbor label create". However, if we need to have our custom error message like the one mentioned in #293, I thought of adding a PreRun. We can also simply raise that error in the Run step itself based on the length of args

@Roaster05 Roaster05 closed this Jan 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants