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

feat: support excluding digest tags #668

Merged
merged 7 commits into from
Nov 3, 2022
Merged
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions cmd/oras/repository/show-tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,19 @@ package repository

import (
"fmt"
"strings"

"github.com/opencontainers/go-digest"
"github.com/spf13/cobra"
"oras.land/oras/cmd/oras/internal/option"
)

type showTagsOptions struct {
option.Remote
option.Common
targetRef string
last string
targetRef string
last string
excludeDigestTag bool
}

func showTagsCmd() *cobra.Command {
Expand All @@ -41,6 +44,12 @@ func showTagsCmd() *cobra.Command {
Example - Show tags of the target repository:
oras repository show-tags localhost:5000/hello

Example - Show tags in the target repository with digest-like tags hidden:
oras repository show-tags localhost:5000/hello --exclude-digest-tag
qweeah marked this conversation as resolved.
Show resolved Hide resolved
qweeah marked this conversation as resolved.
Show resolved Hide resolved
qweeah marked this conversation as resolved.
Show resolved Hide resolved

Example - Show tags of the target repository that include values lexically after last:
oras repository show-tags --last "last_tag" localhost:5000/hello

Example - Show tags of the target repository that include values lexically after last:
oras repository show-tags --last "last_tag" localhost:5000/hello
`,
Expand All @@ -52,6 +61,7 @@ Example - Show tags of the target repository that include values lexically after
},
}
cmd.Flags().StringVar(&opts.last, "last", "", "start after the tag specified by `last`")
cmd.Flags().BoolVar(&opts.excludeDigestTag, "exclude-digest-tags", false, "exclude all digest-like tags")
qweeah marked this conversation as resolved.
Show resolved Hide resolved
option.ApplyFlags(&opts, cmd.Flags())
return cmd
}
Expand All @@ -64,8 +74,17 @@ func showTags(opts showTagsOptions) error {
}
return repo.Tags(ctx, opts.last, func(tags []string) error {
for _, tag := range tags {
if opts.excludeDigestTag && isDigestTag(tag) {
continue
}
fmt.Println(tag)
}
return nil
})
}

func isDigestTag(tag string) bool {
dgst := strings.Replace(tag, "-", ":", 1)
_, err := digest.Parse(dgst)
return err == nil
}