From 9cd0add9348f1ef69c6a9120e4d83b6539023e83 Mon Sep 17 00:00:00 2001 From: Rizul Gupta Date: Fri, 3 Jan 2025 19:20:03 +0530 Subject: [PATCH 1/4] enforce exact argument count for cmds Signed-off-by: Rizul Gupta --- cmd/harbor/root/labels/create.go | 2 +- cmd/harbor/root/labels/list.go | 1 + cmd/harbor/root/project/list.go | 1 + cmd/harbor/root/registry/create.go | 2 +- cmd/harbor/root/registry/list.go | 1 + cmd/harbor/root/user/create.go | 2 +- cmd/harbor/root/user/list.go | 2 +- 7 files changed, 7 insertions(+), 4 deletions(-) diff --git a/cmd/harbor/root/labels/create.go b/cmd/harbor/root/labels/create.go index a336f1de..2fbea0ae 100644 --- a/cmd/harbor/root/labels/create.go +++ b/cmd/harbor/root/labels/create.go @@ -15,7 +15,7 @@ func CreateLabelCommand() *cobra.Command { Short: "create label", Long: "create label in harbor", Example: "harbor label create", - Args: cobra.NoArgs, + Args: cobra.ExactArgs(0), Run: func(cmd *cobra.Command, args []string) { var err error createView := &create.CreateView{ diff --git a/cmd/harbor/root/labels/list.go b/cmd/harbor/root/labels/list.go index 84f127bb..acb9ac81 100644 --- a/cmd/harbor/root/labels/list.go +++ b/cmd/harbor/root/labels/list.go @@ -15,6 +15,7 @@ func ListLabelCommand() *cobra.Command { cmd := &cobra.Command{ Use: "list", Short: "list labels", + Args: cobra.ExactArgs(0), Run: func(cmd *cobra.Command, args []string) { label, err := api.ListLabel(opts) if err != nil { diff --git a/cmd/harbor/root/project/list.go b/cmd/harbor/root/project/list.go index 9fae2bf4..b87a7474 100644 --- a/cmd/harbor/root/project/list.go +++ b/cmd/harbor/root/project/list.go @@ -19,6 +19,7 @@ func ListProjectCommand() *cobra.Command { cmd := &cobra.Command{ Use: "list", Short: "list project", + Args: cobra.ExactArgs(0), Run: func(cmd *cobra.Command, args []string) { if private && public { log.Fatal("Cannot specify both --private and --public flags") diff --git a/cmd/harbor/root/registry/create.go b/cmd/harbor/root/registry/create.go index bf4d93ac..564b14bb 100644 --- a/cmd/harbor/root/registry/create.go +++ b/cmd/harbor/root/registry/create.go @@ -14,7 +14,7 @@ func CreateRegistryCommand() *cobra.Command { Use: "create", Short: "create registry", Example: "harbor registry create", - Args: cobra.NoArgs, + Args: cobra.ExactArgs(0), Run: func(cmd *cobra.Command, args []string) { var err error createView := &api.CreateRegView{ diff --git a/cmd/harbor/root/registry/list.go b/cmd/harbor/root/registry/list.go index c55036f6..c5a362cc 100644 --- a/cmd/harbor/root/registry/list.go +++ b/cmd/harbor/root/registry/list.go @@ -16,6 +16,7 @@ func ListRegistryCommand() *cobra.Command { cmd := &cobra.Command{ Use: "list", Short: "list registry", + Args: cobra.ExactArgs(0), Run: func(cmd *cobra.Command, args []string) { registry, err := api.ListRegistries(opts) diff --git a/cmd/harbor/root/user/create.go b/cmd/harbor/root/user/create.go index 6b873cad..b6146544 100644 --- a/cmd/harbor/root/user/create.go +++ b/cmd/harbor/root/user/create.go @@ -14,7 +14,7 @@ func UserCreateCmd() *cobra.Command { cmd := &cobra.Command{ Use: "create", Short: "create user", - Args: cobra.NoArgs, + Args: cobra.ExactArgs(0), Run: func(cmd *cobra.Command, args []string) { var err error createView := &create.CreateView{ diff --git a/cmd/harbor/root/user/list.go b/cmd/harbor/root/user/list.go index 9a7999e9..99d99b97 100644 --- a/cmd/harbor/root/user/list.go +++ b/cmd/harbor/root/user/list.go @@ -15,7 +15,7 @@ func UserListCmd() *cobra.Command { cmd := &cobra.Command{ Use: "list", Short: "list users", - Args: cobra.NoArgs, + Args: cobra.ExactArgs(0), Aliases: []string{"ls"}, Run: func(cmd *cobra.Command, args []string) { response, err := api.ListUsers(opts) From 3f5f3f337889c22a7d094e02efaaa70f5eb2d4e9 Mon Sep 17 00:00:00 2001 From: Rizul Gupta Date: Sun, 5 Jan 2025 20:16:18 +0530 Subject: [PATCH 2/4] fix: enforce exact argument count for create project command Signed-off-by: Rizul Gupta --- cmd/harbor/root/project/create.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/harbor/root/project/create.go b/cmd/harbor/root/project/create.go index 9366e518..83192fa2 100644 --- a/cmd/harbor/root/project/create.go +++ b/cmd/harbor/root/project/create.go @@ -14,7 +14,7 @@ func CreateProjectCommand() *cobra.Command { cmd := &cobra.Command{ Use: "create [project name]", Short: "create project", - Args: cobra.MaximumNArgs(1), + Args: cobra.ExactArgs(1), Run: func(cmd *cobra.Command, args []string) { var err error createView := &create.CreateView{ From 7dbaffddda4bc92a4fd85906c09e2726741a32cc Mon Sep 17 00:00:00 2001 From: Rizul Gupta Date: Fri, 10 Jan 2025 00:40:14 +0530 Subject: [PATCH 3/4] revert change for project create cmd Signed-off-by: Rizul Gupta --- cmd/harbor/root/project/create.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/harbor/root/project/create.go b/cmd/harbor/root/project/create.go index 83192fa2..9366e518 100644 --- a/cmd/harbor/root/project/create.go +++ b/cmd/harbor/root/project/create.go @@ -14,7 +14,7 @@ func CreateProjectCommand() *cobra.Command { cmd := &cobra.Command{ Use: "create [project name]", Short: "create project", - Args: cobra.ExactArgs(1), + Args: cobra.MaximumNArgs(1), Run: func(cmd *cobra.Command, args []string) { var err error createView := &create.CreateView{ From 0ba634aaa4cfd6bd3bdc52158da8ac0426631424 Mon Sep 17 00:00:00 2001 From: Rizul Gupta Date: Mon, 20 Jan 2025 12:06:22 +0530 Subject: [PATCH 4/4] lint error fix Signed-off-by: Rizul Gupta --- cmd/harbor/root/labels/list.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/harbor/root/labels/list.go b/cmd/harbor/root/labels/list.go index 7b2925da..847dcdcc 100644 --- a/cmd/harbor/root/labels/list.go +++ b/cmd/harbor/root/labels/list.go @@ -28,7 +28,7 @@ func ListLabelCommand() *cobra.Command { cmd := &cobra.Command{ Use: "list", Short: "list labels", - Args: cobra.ExactArgs(0), + Args: cobra.ExactArgs(0), Run: func(cmd *cobra.Command, args []string) { label, err := api.ListLabel(opts) if err != nil {