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

enforce exact argument count for cmds #302

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

rizul2108
Copy link
Contributor

@rizul2108 rizul2108 commented Jan 3, 2025

This PR fixes issue #293 by giving the below error

./harbor-cli project list create
Error: accepts 0 arg(s), received 1

This PR reviewed all commands where the No. of arguments were not specified and addresses that and also replaced cobra.NoArgs with cobra.ExactArgs(0) as later gives more defined error.

It also fixes one more issue that was in project create command when no name for project was gien it gave below error

./harbor-cli project create
credential with name '' not found

so fixes that to give below error

./harbor-cli project create
Error: accepts 1 arg(s), received 0

Signed-off-by: Rizul Gupta <mail2rizul@gmail.com>
@rizul2108
Copy link
Contributor Author

@bupd can you please review this PR

Signed-off-by: Rizul Gupta <mail2rizul@gmail.com>
@rizul2108
Copy link
Contributor Author

@bupd can you please see if this is what was required for the issue

@rizul2108
Copy link
Contributor Author

@Vad1mo is anything else also required ?

Copy link
Member

@bupd bupd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribtions

I left few changes to need to be made.
Also verify the working of all commands.

@@ -15,7 +15,7 @@ func CreateLabelCommand() *cobra.Command {
Short: "create label",
Long: "create label in harbor",
Example: "harbor label create",
Args: cobra.NoArgs,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not needed.

@@ -15,6 +15,7 @@ func ListLabelCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "list",
Short: "list labels",
Args: cobra.ExactArgs(0),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please do cobra.NoArgs

Suggested change
Args: cobra.ExactArgs(0),
Args: cobra.NoArgs,

to maintain consistency

cmd/harbor/root/project/create.go Outdated Show resolved Hide resolved
cmd/harbor/root/project/list.go Show resolved Hide resolved
@rizul2108
Copy link
Contributor Author

I used ExactArgs everywhere as it gives more clear and understandable errors and same error message as mentioned in #293 but NoArgs gives the error message which were mentioned to be avoided in the issue #293

Signed-off-by: Rizul Gupta <mail2rizul@gmail.com>
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