Skip to content

Commit

Permalink
feat: Add ability query tags for oras repo tags command (#800)
Browse files Browse the repository at this point in the history
Signed-off-by: Terry Howe <[email protected]>
  • Loading branch information
Terry Howe authored Feb 23, 2023
1 parent fb68c73 commit 0a34492
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions cmd/oras/repository/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ Example - Show tags of the target OCI layout folder 'layout-dir':
Example - Show tags of the target OCI layout archive 'layout.tar':
oras repo tags --oci-layout layout.tar
Example - Show tags associated with a particular tagged resource:
oras repo tags localhost:5000/hello:latest
Example - Show tags associated with a digest:
oras repo tags localhost:5000/hello@sha256:c551125a624189cece9135981621f3f3144564ddabe14b523507bf74c2281d9b
`,
Args: cobra.ExactArgs(1),
Aliases: []string{"show-tags"},
Expand All @@ -73,19 +79,43 @@ Example - Show tags of the target OCI layout archive 'layout.tar':
}

func showTags(opts showTagsOptions) error {
ctx, _ := opts.SetLoggerLevel()
ctx, logger := opts.SetLoggerLevel()
finder, err := opts.NewReadonlyTarget(ctx, opts.Common)
if err != nil {
return err
}
filter := ""
if opts.Reference != "" {
return fmt.Errorf("unexpected tag or digest %q found in repository reference %q", opts.Reference, opts.RawReference)
_, err := digest.Parse(opts.Reference)
if err == nil {
filter = opts.Reference
} else {
desc, err := finder.Resolve(ctx, opts.Reference)
if err != nil {
return err
}
filter = desc.Digest.String()
}
logger.Infof("[Preview] Querying tags associated to %s, it may take a while.\n", filter)
}
return finder.Tags(ctx, opts.last, func(tags []string) error {
for _, tag := range tags {
if opts.excludeDigestTag && isDigestTag(tag) {
continue
}
if filter != "" {
if tag == opts.Reference {
fmt.Println(tag)
continue
}
desc, err := finder.Resolve(ctx, tag)
if err != nil {
return err
}
if desc.Digest.String() != filter {
continue
}
}
fmt.Println(tag)
}
return nil
Expand Down

0 comments on commit 0a34492

Please sign in to comment.