From 37af5af5b80548238daf6188d91f780338568d17 Mon Sep 17 00:00:00 2001 From: NucleoFusion Date: Thu, 12 Feb 2026 11:01:07 +0530 Subject: [PATCH 1/3] refactor(artifact): refactoring scan and tag subcommands under artifact commands Signed-off-by: NucleoFusion --- cmd/harbor/root/artifact/cmd.go | 6 +- cmd/harbor/root/artifact/scan/scan.go | 33 ++++ .../root/artifact/{scan.go => scan/start.go} | 53 +----- cmd/harbor/root/artifact/scan/stop.go | 58 +++++++ cmd/harbor/root/artifact/tags.go | 160 ------------------ cmd/harbor/root/artifact/tags/create.go | 63 +++++++ cmd/harbor/root/artifact/tags/delete.go | 62 +++++++ cmd/harbor/root/artifact/tags/list.go | 77 +++++++++ cmd/harbor/root/artifact/tags/tags.go | 35 ++++ 9 files changed, 333 insertions(+), 214 deletions(-) create mode 100644 cmd/harbor/root/artifact/scan/scan.go rename cmd/harbor/root/artifact/{scan.go => scan/start.go} (55%) create mode 100644 cmd/harbor/root/artifact/scan/stop.go delete mode 100644 cmd/harbor/root/artifact/tags.go create mode 100644 cmd/harbor/root/artifact/tags/create.go create mode 100644 cmd/harbor/root/artifact/tags/delete.go create mode 100644 cmd/harbor/root/artifact/tags/list.go create mode 100644 cmd/harbor/root/artifact/tags/tags.go diff --git a/cmd/harbor/root/artifact/cmd.go b/cmd/harbor/root/artifact/cmd.go index 0a70203e..6141b681 100644 --- a/cmd/harbor/root/artifact/cmd.go +++ b/cmd/harbor/root/artifact/cmd.go @@ -15,6 +15,8 @@ package artifact import ( "github.com/goharbor/harbor-cli/cmd/harbor/root/artifact/label" + artifactscan "github.com/goharbor/harbor-cli/cmd/harbor/root/artifact/scan" + artifacttags "github.com/goharbor/harbor-cli/cmd/harbor/root/artifact/tags" "github.com/spf13/cobra" ) @@ -30,8 +32,8 @@ func Artifact() *cobra.Command { ListArtifactCommand(), ViewArtifactCommmand(), DeleteArtifactCommand(), - ScanArtifactCommand(), - ArtifactTagsCmd(), + artifactscan.ScanArtifactCommand(), + artifacttags.ArtifactTagsCmd(), label.LabelsArtifactCommmand(), ) diff --git a/cmd/harbor/root/artifact/scan/scan.go b/cmd/harbor/root/artifact/scan/scan.go new file mode 100644 index 00000000..8f2b2330 --- /dev/null +++ b/cmd/harbor/root/artifact/scan/scan.go @@ -0,0 +1,33 @@ +// Copyright Project Harbor Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +package artifactscan + +import "github.com/spf13/cobra" + +func ScanArtifactCommand() *cobra.Command { + cmd := &cobra.Command{ + Use: "scan", + Short: "Scan an artifact", + Long: `Scan an artifact in Harbor Repository`, + Example: `harbor artifact scan start //`, + } + + cmd.AddCommand( + StartScanArtifactCommand(), + StopScanArtifactCommand(), + // LogScanArtifactCommand(), + ) + + return cmd +} diff --git a/cmd/harbor/root/artifact/scan.go b/cmd/harbor/root/artifact/scan/start.go similarity index 55% rename from cmd/harbor/root/artifact/scan.go rename to cmd/harbor/root/artifact/scan/start.go index 4040e62f..eaeaf5d2 100644 --- a/cmd/harbor/root/artifact/scan.go +++ b/cmd/harbor/root/artifact/scan/start.go @@ -11,7 +11,7 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. -package artifact +package artifactscan import ( "fmt" @@ -19,27 +19,9 @@ import ( "github.com/goharbor/harbor-cli/pkg/api" "github.com/goharbor/harbor-cli/pkg/prompt" "github.com/goharbor/harbor-cli/pkg/utils" - log "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) -func ScanArtifactCommand() *cobra.Command { - cmd := &cobra.Command{ - Use: "scan", - Short: "Scan an artifact", - Long: `Scan an artifact in Harbor Repository`, - Example: `harbor artifact scan start //`, - } - - cmd.AddCommand( - StartScanArtifactCommand(), - StopScanArtifactCommand(), - // LogScanArtifactCommand(), - ) - - return cmd -} - func StartScanArtifactCommand() *cobra.Command { cmd := &cobra.Command{ Use: "start", @@ -72,36 +54,3 @@ func StartScanArtifactCommand() *cobra.Command { } return cmd } - -func StopScanArtifactCommand() *cobra.Command { - cmd := &cobra.Command{ - Use: "stop", - Short: "Stop a scan of an artifact", - Long: `Stop a scan of an artifact in Harbor Repository`, - Example: `harbor artifact scan stop //`, - Run: func(cmd *cobra.Command, args []string) { - var err error - var projectName, repoName, reference string - - if len(args) > 0 { - projectName, repoName, reference, err = utils.ParseProjectRepoReference(args[0]) - if err != nil { - log.Errorf("failed to parse project/repo/reference: %v", err) - } - } else { - projectName, err = prompt.GetProjectNameFromUser() - if err != nil { - log.Errorf("failed to get project name: %v", utils.ParseHarborErrorMsg(err)) - } - repoName = prompt.GetRepoNameFromUser(projectName) - reference = prompt.GetReferenceFromUser(repoName, projectName) - } - - err = api.StopScanArtifact(projectName, repoName, reference) - if err != nil { - log.Errorf("failed to stop scan of artifact: %v", err) - } - }, - } - return cmd -} diff --git a/cmd/harbor/root/artifact/scan/stop.go b/cmd/harbor/root/artifact/scan/stop.go new file mode 100644 index 00000000..9ce0bfc7 --- /dev/null +++ b/cmd/harbor/root/artifact/scan/stop.go @@ -0,0 +1,58 @@ +// Copyright Project Harbor Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +package artifactscan + +import ( + "fmt" + + "github.com/goharbor/harbor-cli/pkg/api" + "github.com/goharbor/harbor-cli/pkg/prompt" + "github.com/goharbor/harbor-cli/pkg/utils" + "github.com/spf13/cobra" +) + +func StopScanArtifactCommand() *cobra.Command { + cmd := &cobra.Command{ + Use: "stop", + Short: "Stop a scan of an artifact", + Long: `Stop a scan of an artifact in Harbor Repository`, + Example: `harbor artifact scan stop //`, + RunE: func(cmd *cobra.Command, args []string) error { + var err error + var projectName, repoName, reference string + + if len(args) > 0 { + projectName, repoName, reference, err = utils.ParseProjectRepoReference(args[0]) + if err != nil { + return fmt.Errorf("failed to parse project/repo/reference: %v", err) + } + } else { + projectName, err = prompt.GetProjectNameFromUser() + if err != nil { + return fmt.Errorf("failed to get project name: %v", utils.ParseHarborErrorMsg(err)) + } + repoName = prompt.GetRepoNameFromUser(projectName) + reference = prompt.GetReferenceFromUser(repoName, projectName) + } + + err = api.StopScanArtifact(projectName, repoName, reference) + if err != nil { + return fmt.Errorf("failed to stop scan of artifact: %v", err) + } + + return nil + }, + } + return cmd +} diff --git a/cmd/harbor/root/artifact/tags.go b/cmd/harbor/root/artifact/tags.go deleted file mode 100644 index 4f9a60f5..00000000 --- a/cmd/harbor/root/artifact/tags.go +++ /dev/null @@ -1,160 +0,0 @@ -// Copyright Project Harbor Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -package artifact - -import ( - "github.com/goharbor/go-client/pkg/sdk/v2.0/client/artifact" - "github.com/goharbor/harbor-cli/pkg/api" - "github.com/goharbor/harbor-cli/pkg/prompt" - "github.com/goharbor/harbor-cli/pkg/utils" - "github.com/goharbor/harbor-cli/pkg/views/artifact/tags/create" - "github.com/goharbor/harbor-cli/pkg/views/artifact/tags/list" - log "github.com/sirupsen/logrus" - "github.com/spf13/cobra" - "github.com/spf13/viper" -) - -func ArtifactTagsCmd() *cobra.Command { - cmd := &cobra.Command{ - Use: "tags", - Short: "Manage tags of an artifact", - Example: ` harbor artifact tags list //`, - } - - cmd.AddCommand( - ListTagsCmd(), - DeleteTagsCmd(), - CreateTagsCmd(), - ) - - return cmd -} - -func CreateTagsCmd() *cobra.Command { - cmd := &cobra.Command{ - Use: "create", - Short: "Create a tag of an artifact", - Example: `harbor artifact tags create // `, - Run: func(cmd *cobra.Command, args []string) { - var err error - var projectName, repoName, reference string - var tagName string - if len(args) > 0 { - projectName, repoName, reference, err = utils.ParseProjectRepoReference(args[0]) - if err != nil { - log.Errorf("failed to parse project/repo/reference: %v", err) - } - tagName = args[1] - } else { - projectName, err = prompt.GetProjectNameFromUser() - if err != nil { - log.Errorf("failed to get project name: %v", utils.ParseHarborErrorMsg(err)) - } - repoName = prompt.GetRepoNameFromUser(projectName) - reference = prompt.GetReferenceFromUser(repoName, projectName) - create.CreateTagView(&tagName) - } - err = api.CreateTag(projectName, repoName, reference, tagName) - if err != nil { - log.Errorf("failed to create tag: %v", err) - } - }, - } - - return cmd -} - -func ListTagsCmd() *cobra.Command { - cmd := &cobra.Command{ - Use: "list", - Short: "List tags of an artifact", - Example: `harbor artifact tags list //`, - Run: func(cmd *cobra.Command, args []string) { - var err error - var tags *artifact.ListTagsOK - var projectName, repoName, reference string - - if len(args) > 0 { - projectName, repoName, reference, err = utils.ParseProjectRepoReference(args[0]) - if err != nil { - log.Errorf("failed to parse project/repo/reference: %v", err) - } - } else { - projectName, err = prompt.GetProjectNameFromUser() - if err != nil { - log.Errorf("failed to get project name: %v", utils.ParseHarborErrorMsg(err)) - } - repoName = prompt.GetRepoNameFromUser(projectName) - if repoName == "" { - return - } - reference = prompt.GetReferenceFromUser(repoName, projectName) - } - - tags, err = api.ListTags(projectName, repoName, reference) - - if err != nil { - log.Errorf("failed to list tags: %v", err) - return - } - - FormatFlag := viper.GetString("output-format") - if FormatFlag != "" { - err = utils.PrintFormat(tags, FormatFlag) - if err != nil { - log.Error(err) - return - } - } else { - list.ListTags(tags.Payload) - } - }, - } - - return cmd -} - -func DeleteTagsCmd() *cobra.Command { - cmd := &cobra.Command{ - Use: "delete", - Short: "Delete a tag of an artifact", - Example: `harbor artifact tags delete // `, - Run: func(cmd *cobra.Command, args []string) { - var err error - var projectName, repoName, reference string - var tagName string - if len(args) > 0 { - projectName, repoName, reference, err = utils.ParseProjectRepoReference(args[0]) - if err != nil { - log.Errorf("failed to parse project/repo/reference: %v", err) - } - tagName = args[1] - } else { - projectName, err = prompt.GetProjectNameFromUser() - if err != nil { - log.Errorf("failed to get project name: %v", utils.ParseHarborErrorMsg(err)) - } - repoName = prompt.GetRepoNameFromUser(projectName) - reference = prompt.GetReferenceFromUser(repoName, projectName) - tagName = prompt.GetTagFromUser(repoName, projectName, reference) - } - err = api.DeleteTag(projectName, repoName, reference, tagName) - if err != nil { - log.Errorf("failed to delete tag: %v", err) - } - }, - } - - return cmd -} diff --git a/cmd/harbor/root/artifact/tags/create.go b/cmd/harbor/root/artifact/tags/create.go new file mode 100644 index 00000000..9ebeb312 --- /dev/null +++ b/cmd/harbor/root/artifact/tags/create.go @@ -0,0 +1,63 @@ +// Copyright Project Harbor Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +package artifacttags + +import ( + "fmt" + + "github.com/goharbor/harbor-cli/pkg/api" + "github.com/goharbor/harbor-cli/pkg/prompt" + "github.com/goharbor/harbor-cli/pkg/utils" + "github.com/goharbor/harbor-cli/pkg/views/artifact/tags/create" + "github.com/spf13/cobra" +) + +func CreateTagsCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: "create", + Short: "Create a tag of an artifact", + Example: `harbor artifact tags create // `, + RunE: func(cmd *cobra.Command, args []string) error { + var err error + var projectName, repoName, reference string + var tagName string + + if len(args) > 0 { + projectName, repoName, reference, err = utils.ParseProjectRepoReference(args[0]) + if err != nil { + return fmt.Errorf("failed to parse project/repo/reference: %v", err) + } + + tagName = args[1] + } else { + projectName, err = prompt.GetProjectNameFromUser() + if err != nil { + return fmt.Errorf("failed to get project name: %v", utils.ParseHarborErrorMsg(err)) + } + + repoName = prompt.GetRepoNameFromUser(projectName) + reference = prompt.GetReferenceFromUser(repoName, projectName) + create.CreateTagView(&tagName) + } + err = api.CreateTag(projectName, repoName, reference, tagName) + if err != nil { + return fmt.Errorf("failed to create tag: %v", err) + } + + return nil + }, + } + + return cmd +} diff --git a/cmd/harbor/root/artifact/tags/delete.go b/cmd/harbor/root/artifact/tags/delete.go new file mode 100644 index 00000000..8d6090af --- /dev/null +++ b/cmd/harbor/root/artifact/tags/delete.go @@ -0,0 +1,62 @@ +// Copyright Project Harbor Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +package artifacttags + +import ( + "fmt" + + "github.com/goharbor/harbor-cli/pkg/api" + "github.com/goharbor/harbor-cli/pkg/prompt" + "github.com/goharbor/harbor-cli/pkg/utils" + "github.com/spf13/cobra" +) + +func DeleteTagsCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: "delete", + Short: "Delete a tag of an artifact", + Example: `harbor artifact tags delete // `, + RunE: func(cmd *cobra.Command, args []string) error { + var err error + var projectName, repoName, reference string + var tagName string + if len(args) > 0 { + projectName, repoName, reference, err = utils.ParseProjectRepoReference(args[0]) + if err != nil { + return fmt.Errorf("failed to parse project/repo/reference: %v", err) + } + + tagName = args[1] + } else { + projectName, err = prompt.GetProjectNameFromUser() + if err != nil { + return fmt.Errorf("failed to get project name: %v", utils.ParseHarborErrorMsg(err)) + } + + repoName = prompt.GetRepoNameFromUser(projectName) + reference = prompt.GetReferenceFromUser(repoName, projectName) + tagName = prompt.GetTagFromUser(repoName, projectName, reference) + } + + err = api.DeleteTag(projectName, repoName, reference, tagName) + if err != nil { + return fmt.Errorf("failed to delete tag: %v", err) + } + + return nil + }, + } + + return cmd +} diff --git a/cmd/harbor/root/artifact/tags/list.go b/cmd/harbor/root/artifact/tags/list.go new file mode 100644 index 00000000..9d057460 --- /dev/null +++ b/cmd/harbor/root/artifact/tags/list.go @@ -0,0 +1,77 @@ +// Copyright Project Harbor Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package artifacttags + +import ( + "fmt" + + "github.com/goharbor/go-client/pkg/sdk/v2.0/client/artifact" + "github.com/goharbor/harbor-cli/pkg/api" + "github.com/goharbor/harbor-cli/pkg/prompt" + "github.com/goharbor/harbor-cli/pkg/utils" + "github.com/goharbor/harbor-cli/pkg/views/artifact/tags/list" + "github.com/spf13/cobra" + "github.com/spf13/viper" +) + +func ListTagsCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: "list", + Short: "List tags of an artifact", + Example: `harbor artifact tags list //`, + RunE: func(cmd *cobra.Command, args []string) error { + var err error + var tags *artifact.ListTagsOK + var projectName, repoName, reference string + + if len(args) > 0 { + projectName, repoName, reference, err = utils.ParseProjectRepoReference(args[0]) + if err != nil { + return fmt.Errorf("failed to parse project/repo/reference: %v", err) + } + } else { + projectName, err = prompt.GetProjectNameFromUser() + if err != nil { + return fmt.Errorf("failed to get project name: %v", utils.ParseHarborErrorMsg(err)) + } + + repoName = prompt.GetRepoNameFromUser(projectName) + if repoName == "" { + return fmt.Errorf("invalid repository name provided") + } + reference = prompt.GetReferenceFromUser(repoName, projectName) + } + + tags, err = api.ListTags(projectName, repoName, reference) + if err != nil { + return fmt.Errorf("failed to list tags: %v", err) + } + + FormatFlag := viper.GetString("output-format") + if FormatFlag != "" { + err = utils.PrintFormat(tags, FormatFlag) + if err != nil { + return err + } + } else { + list.ListTags(tags.Payload) + } + + return nil + }, + } + + return cmd +} diff --git a/cmd/harbor/root/artifact/tags/tags.go b/cmd/harbor/root/artifact/tags/tags.go new file mode 100644 index 00000000..d30b01e6 --- /dev/null +++ b/cmd/harbor/root/artifact/tags/tags.go @@ -0,0 +1,35 @@ +// Copyright Project Harbor Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +package artifacttags + +import ( + "github.com/spf13/cobra" +) + +func ArtifactTagsCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: "tags", + Short: "Manage tags of an artifact", + Example: ` harbor artifact tags list //`, + } + + cmd.AddCommand( + ListTagsCmd(), + DeleteTagsCmd(), + CreateTagsCmd(), + ) + + return cmd +} + From 3407f3f7cba4285b105fcdf152564084adf6fe81 Mon Sep 17 00:00:00 2001 From: NucleoFusion Date: Tue, 3 Mar 2026 21:01:22 +0530 Subject: [PATCH 2/3] fix: lint error Signed-off-by: NucleoFusion --- cmd/harbor/root/artifact/scan/scan.go | 21 ++++++++++++++++++++- cmd/harbor/root/artifact/scan/start.go | 21 ++++----------------- cmd/harbor/root/artifact/scan/stop.go | 20 +++----------------- 3 files changed, 27 insertions(+), 35 deletions(-) diff --git a/cmd/harbor/root/artifact/scan/scan.go b/cmd/harbor/root/artifact/scan/scan.go index 8f2b2330..949fa200 100644 --- a/cmd/harbor/root/artifact/scan/scan.go +++ b/cmd/harbor/root/artifact/scan/scan.go @@ -13,7 +13,11 @@ // limitations under the License. package artifactscan -import "github.com/spf13/cobra" +import ( + "github.com/goharbor/harbor-cli/pkg/prompt" + "github.com/goharbor/harbor-cli/pkg/utils" + "github.com/spf13/cobra" +) func ScanArtifactCommand() *cobra.Command { cmd := &cobra.Command{ @@ -31,3 +35,18 @@ func ScanArtifactCommand() *cobra.Command { return cmd } + +func parseArgs(args []string) (string, string, string, error) { + if len(args) > 0 { + return utils.ParseProjectRepoReference(args[0]) + } else { + projectName, err := prompt.GetProjectNameFromUser() + if err != nil { + return "", "", "", err + } + repoName := prompt.GetRepoNameFromUser(projectName) + reference := prompt.GetReferenceFromUser(repoName, projectName) + + return projectName, repoName, reference, nil + } +} diff --git a/cmd/harbor/root/artifact/scan/start.go b/cmd/harbor/root/artifact/scan/start.go index eaeaf5d2..a1aa732a 100644 --- a/cmd/harbor/root/artifact/scan/start.go +++ b/cmd/harbor/root/artifact/scan/start.go @@ -17,8 +17,6 @@ import ( "fmt" "github.com/goharbor/harbor-cli/pkg/api" - "github.com/goharbor/harbor-cli/pkg/prompt" - "github.com/goharbor/harbor-cli/pkg/utils" "github.com/spf13/cobra" ) @@ -29,22 +27,11 @@ func StartScanArtifactCommand() *cobra.Command { Long: `Start a scan of an artifact in Harbor Repository`, Example: `harbor artifact scan start //`, RunE: func(cmd *cobra.Command, args []string) error { - var err error - var projectName, repoName, reference string - - if len(args) > 0 { - projectName, repoName, reference, err = utils.ParseProjectRepoReference(args[0]) - if err != nil { - return fmt.Errorf("failed to parse project/repo/reference: %v", err) - } - } else { - projectName, err = prompt.GetProjectNameFromUser() - if err != nil { - return fmt.Errorf("failed to get project name: %v", utils.ParseHarborErrorMsg(err)) - } - repoName = prompt.GetRepoNameFromUser(projectName) - reference = prompt.GetReferenceFromUser(repoName, projectName) + projectName, repoName, reference, err := parseArgs(args) + if err != nil { + return err } + err = api.StartScanArtifact(projectName, repoName, reference) if err != nil { return fmt.Errorf("failed to start scan of artifact: %v", err) diff --git a/cmd/harbor/root/artifact/scan/stop.go b/cmd/harbor/root/artifact/scan/stop.go index 9ce0bfc7..9ec132c9 100644 --- a/cmd/harbor/root/artifact/scan/stop.go +++ b/cmd/harbor/root/artifact/scan/stop.go @@ -17,8 +17,6 @@ import ( "fmt" "github.com/goharbor/harbor-cli/pkg/api" - "github.com/goharbor/harbor-cli/pkg/prompt" - "github.com/goharbor/harbor-cli/pkg/utils" "github.com/spf13/cobra" ) @@ -29,21 +27,9 @@ func StopScanArtifactCommand() *cobra.Command { Long: `Stop a scan of an artifact in Harbor Repository`, Example: `harbor artifact scan stop //`, RunE: func(cmd *cobra.Command, args []string) error { - var err error - var projectName, repoName, reference string - - if len(args) > 0 { - projectName, repoName, reference, err = utils.ParseProjectRepoReference(args[0]) - if err != nil { - return fmt.Errorf("failed to parse project/repo/reference: %v", err) - } - } else { - projectName, err = prompt.GetProjectNameFromUser() - if err != nil { - return fmt.Errorf("failed to get project name: %v", utils.ParseHarborErrorMsg(err)) - } - repoName = prompt.GetRepoNameFromUser(projectName) - reference = prompt.GetReferenceFromUser(repoName, projectName) + projectName, repoName, reference, err := parseArgs(args) + if err != nil { + return err } err = api.StopScanArtifact(projectName, repoName, reference) From e9f511cfedf1a061a631562fd4095729cef07c02 Mon Sep 17 00:00:00 2001 From: NucleoFusion Date: Tue, 3 Mar 2026 21:04:13 +0530 Subject: [PATCH 3/3] fix: lint error Signed-off-by: NucleoFusion --- cmd/harbor/root/artifact/tags/tags.go | 1 - 1 file changed, 1 deletion(-) diff --git a/cmd/harbor/root/artifact/tags/tags.go b/cmd/harbor/root/artifact/tags/tags.go index d30b01e6..1433f1d4 100644 --- a/cmd/harbor/root/artifact/tags/tags.go +++ b/cmd/harbor/root/artifact/tags/tags.go @@ -32,4 +32,3 @@ func ArtifactTagsCmd() *cobra.Command { return cmd } -