Skip to content

Commit

Permalink
feat: support oras discover pass pagination args
Browse files Browse the repository at this point in the history
Signed-off-by: njucjc <njucjc@gmail.com>
  • Loading branch information
njucjc committed Nov 6, 2024
1 parent 0013d4c commit 5660be4
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions cmd/oras/root/discover.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (

ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/spf13/cobra"
"oras.land/oras-go/v2/registry/remote"

"oras.land/oras-go/v2"
"oras.land/oras-go/v2/registry"
Expand All @@ -40,6 +41,7 @@ type discoverOptions struct {
option.Format

artifactType string
pageSize int
}

func discoverCmd() *cobra.Command {
Expand Down Expand Up @@ -98,6 +100,9 @@ Example - Discover referrers of the manifest tagged 'v1' in an OCI image layout
}

cmd.Flags().StringVarP(&opts.artifactType, "artifact-type", "", "", "artifact type")
// If zero, the page size is determined by the remote registry.
// Reference: https://github.com/opencontainers/distribution-spec/blob/v1.1.0/spec.md#listing-referrers
cmd.Flags().IntVarP(&opts.pageSize, "page-size", "", 0, "page size for discover pagination")
cmd.Flags().StringVarP(&opts.Format.FormatFlag, "output", "o", "tree", "[Deprecated] format in which to display referrers (table, json, or tree). tree format will also show indirect referrers")
opts.SetTypes(
option.FormatTypeTree,
Expand All @@ -116,6 +121,11 @@ func runDiscover(cmd *cobra.Command, opts *discoverOptions) error {
if err != nil {
return err
}
if r, ok := repo.(*remote.Repository); ok {
if opts.pageSize > 0 {

Check warning on line 125 in cmd/oras/root/discover.go

View check run for this annotation

Codecov / codecov/patch

cmd/oras/root/discover.go#L124-L125

Added lines #L124 - L125 were not covered by tests
r.ReferrerListPageSize = opts.pageSize
}
}

Check warning on line 128 in cmd/oras/root/discover.go

View check run for this annotation

Codecov / codecov/patch

cmd/oras/root/discover.go#L128

Added line #L128 was not covered by tests
if err := opts.EnsureReferenceNotEmpty(cmd, true); err != nil {
return err
}
Expand Down

0 comments on commit 5660be4

Please sign in to comment.