-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add handler function for the commands
Signed-off-by: amands98 <amandeepsm.in@gmail.com>
- Loading branch information
Showing
30 changed files
with
637 additions
and
520 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package artifact | ||
|
||
import ( | ||
"github.com/goharbor/harbor-cli/pkg/api" | ||
"github.com/goharbor/harbor-cli/pkg/utils" | ||
log "github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func ArtifactTagsCmd() *cobra.Command { | ||
|
||
cmd := &cobra.Command{ | ||
Use: "tags", | ||
Short: "Manage tags of an artifact", | ||
Example: ` harbor artifact tags list <project>/<repository>/<reference>`, | ||
} | ||
|
||
cmd.AddCommand( | ||
ListTagsCommand(), | ||
DeleteTagsCmd(), | ||
) | ||
|
||
return cmd | ||
} | ||
|
||
func ListTagsCommand() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "list", | ||
Short: "List tags of an artifact", | ||
Example: `harbor artifact tags list <project>/<repository>/<reference>`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
var err error | ||
if len(args) > 0 { | ||
projectName, repoName, reference := utils.ParseProjectRepoReference(args[0]) | ||
err = api.ListTags(projectName, repoName, reference) | ||
} else { | ||
projectName := utils.GetProjectNameFromUser() | ||
repoName := utils.GetRepoNameFromUser(projectName) | ||
reference := utils.GetReferenceFromUser(repoName, projectName) | ||
err = api.ListTags(projectName, repoName, reference) | ||
} | ||
if err != nil { | ||
log.Errorf("failed to list tags of an artifact: %v", err) | ||
} | ||
|
||
}, | ||
} | ||
|
||
return cmd | ||
} | ||
|
||
func DeleteTagsCmd() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "delete", | ||
Short: "Delete a tag of an artifact", | ||
Example: `harbor artifact tags delete <project>/<repository>/<reference> <tag>`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
var err error | ||
if len(args) > 0 { | ||
projectName, repoName, reference := utils.ParseProjectRepoReference(args[0]) | ||
tag := args[1] | ||
err = api.DeleteTag(projectName, repoName, reference, tag) | ||
} else { | ||
projectName := utils.GetProjectNameFromUser() | ||
repoName := utils.GetRepoNameFromUser(projectName) | ||
reference := utils.GetReferenceFromUser(repoName, projectName) | ||
tag := utils.GetTagFromUser(repoName, projectName, reference) | ||
err = api.DeleteTag(projectName, repoName, reference, tag) | ||
} | ||
if err != nil { | ||
log.Errorf("failed to delete a tag of an artifact: %v", err) | ||
} | ||
}, | ||
} | ||
|
||
return cmd | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.