Skip to content

Commit

Permalink
Merge branch 'main' into renderer-pull
Browse files Browse the repository at this point in the history
  • Loading branch information
Xiaoxuan Wang committed Feb 6, 2025
2 parents 5f1e3e9 + 05e97ed commit 52800e0
Show file tree
Hide file tree
Showing 12 changed files with 20 additions and 16 deletions.
4 changes: 2 additions & 2 deletions cmd/oras/internal/display/metadata/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ type AttachHandler interface {

// DiscoverHandler handles metadata output for discover events.
type DiscoverHandler interface {
Renderer

// MultiLevelSupported returns true if the handler supports multi-level
// discovery.
MultiLevelSupported() bool
// OnDiscovered is called after a referrer is discovered.
OnDiscovered(referrer, subject ocispec.Descriptor) error
// OnCompleted is called when referrer discovery is completed.
OnCompleted() error
}

// ManifestFetchHandler handles metadata output for manifest fetch events.
Expand Down
4 changes: 2 additions & 2 deletions cmd/oras/internal/display/metadata/json/discover.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (h *discoverHandler) OnDiscovered(referrer, subject ocispec.Descriptor) err
return nil
}

// OnCompleted implements metadata.DiscoverHandler.
func (h *discoverHandler) OnCompleted() error {
// Render implements metadata.DiscoverHandler.
func (h *discoverHandler) Render() error {
return output.PrintPrettyJSON(h.out, model.NewDiscover(h.path, h.referrers))
}
4 changes: 2 additions & 2 deletions cmd/oras/internal/display/metadata/table/discover.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ func (h *discoverHandler) OnDiscovered(referrer, subject ocispec.Descriptor) err
return nil
}

// OnCompleted implements metadata.DiscoverHandler.
func (h *discoverHandler) OnCompleted() error {
// Render implements metadata.DiscoverHandler.
func (h *discoverHandler) Render() error {
if n := len(h.referrers); n > 1 {
fmt.Fprintln(h.out, "Discovered", n, "artifacts referencing", h.rawReference)
} else {
Expand Down
4 changes: 2 additions & 2 deletions cmd/oras/internal/display/metadata/template/discover.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (h *discoverHandler) OnDiscovered(referrer, subject ocispec.Descriptor) err
return nil
}

// OnCompleted implements metadata.DiscoverHandler.
func (h *discoverHandler) OnCompleted() error {
// Render implements metadata.DiscoverHandler.
func (h *discoverHandler) Render() error {
return output.ParseAndWrite(h.out, model.NewDiscover(h.path, h.referrers), h.template)
}
4 changes: 2 additions & 2 deletions cmd/oras/internal/display/metadata/tree/discover.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (h *discoverHandler) OnDiscovered(referrer, subject ocispec.Descriptor) err
return nil
}

// OnCompleted implements metadata.DiscoverHandler.
func (h *discoverHandler) OnCompleted() error {
// Render implements metadata.DiscoverHandler.
func (h *discoverHandler) Render() error {
return tree.NewPrinter(h.out).Print(h.root)
}
4 changes: 2 additions & 2 deletions cmd/oras/internal/option/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,15 @@ func (f *Format) SetTypes(defaultType *FormatType, otherTypes ...*FormatType) {

// ApplyFlags implements FlagProvider.ApplyFlag.
func (opts *Format) ApplyFlags(fs *pflag.FlagSet) {
buf := bytes.NewBufferString("[Experimental] Format output using a custom template:")
buf := bytes.NewBufferString("[Experimental] format output using a custom template:")
w := tabwriter.NewWriter(buf, 0, 0, 2, ' ', 0)
for _, t := range opts.allowedTypes {
_, _ = fmt.Fprintf(w, "\n'%s':\t%s", t.Name, t.Usage)
}
_ = w.Flush()
// apply flags
fs.StringVar(&opts.FormatFlag, "format", opts.FormatFlag, buf.String())
fs.StringVar(&opts.Template, "template", "", "[Experimental] Template string used to format output")
fs.StringVar(&opts.Template, "template", "", "[Experimental] template string used to format output")
}

// Parse parses the input format flag.
Expand Down
2 changes: 1 addition & 1 deletion cmd/oras/internal/option/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (opts *Target) AnnotatedReference() string {
func (opts *Target) applyFlagsWithPrefix(fs *pflag.FlagSet, prefix, description string) {
flagPrefix, notePrefix := applyPrefix(prefix, description)
fs.BoolVarP(&opts.IsOCILayout, flagPrefix+"oci-layout", "", false, "set "+notePrefix+"target as an OCI image layout")
fs.StringVar(&opts.Path, flagPrefix+"oci-layout-path", "", "set the path for the "+notePrefix+"OCI image layout target")
fs.StringVar(&opts.Path, flagPrefix+"oci-layout-path", "", "[Experimental] set the path for the "+notePrefix+"OCI image layout target")
}

// ApplyFlagsWithPrefix applies flags to a command flag set with a prefix string.
Expand Down
2 changes: 1 addition & 1 deletion cmd/oras/root/discover.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func runDiscover(cmd *cobra.Command, opts *discoverOptions) error {
}
}
}
return handler.OnCompleted()
return handler.Render()
}

func fetchAllReferrers(ctx context.Context, repo oras.ReadOnlyGraphTarget, desc ocispec.Descriptor, artifactType string, handler metadata.DiscoverHandler) error {
Expand Down
2 changes: 1 addition & 1 deletion cmd/oras/root/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ func runPush(cmd *cobra.Command, opts *pushOptions) error {
copyWithScopeHint := func(root ocispec.Descriptor) error {
// add both pull and push scope hints for dst repository
// to save potential push-scope token requests during copy
ctx = registryutil.WithScopeHint(ctx, dst, auth.ActionPull, auth.ActionPush)
ctx = registryutil.WithScopeHint(ctx, originalDst, auth.ActionPull, auth.ActionPush)

if tag := opts.Reference; tag == "" {
err = oras.CopyGraph(ctx, union, dst, root, copyOptions.CopyGraphOptions)
Expand Down
4 changes: 3 additions & 1 deletion test/e2e/suite/command/cp.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,12 @@ func cpTestRepo(text string) string {
var _ = Describe("ORAS beginners:", func() {
When("running cp command", func() {
It("should show help doc with feature flags", func() {
out := ORAS("cp", "--help").MatchKeyWords("Copy", ExampleDesc).Exec()
out := ORAS("cp", "--help").MatchKeyWords("Copy", ExampleDesc).Exec().Out
Expect(out).Should(gbytes.Say("--from-distribution-spec string\\s+%s", regexp.QuoteMeta(feature.Preview.Mark)))
Expect(out).Should(gbytes.Say("--from-oci-layout-path string\\s+%s", regexp.QuoteMeta(feature.Experimental.Mark)))
Expect(out).Should(gbytes.Say("-r, --recursive\\s+%s", regexp.QuoteMeta(feature.Preview.Mark)))
Expect(out).Should(gbytes.Say("--to-distribution-spec string\\s+%s", regexp.QuoteMeta(feature.Preview.Mark)))
Expect(out).Should(gbytes.Say("--to-oci-layout-path string\\s+%s", regexp.QuoteMeta(feature.Experimental.Mark)))
})

It("should not show --verbose in help doc", func() {
Expand Down
1 change: 1 addition & 0 deletions test/e2e/suite/command/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ var _ = Describe("ORAS beginners:", func() {
It("should show help description with feature flags", func() {
out := ORAS("pull", "--help").MatchKeyWords(ExampleDesc).Exec().Out
gomega.Expect(out).Should(gbytes.Say("--include-subject\\s+%s", regexp.QuoteMeta(feature.Preview.Mark)))
gomega.Expect(out).Should(gbytes.Say("--oci-layout-path string\\s+%s", regexp.QuoteMeta(feature.Experimental.Mark)))
})

It("should not show --verbose in help doc", func() {
Expand Down
1 change: 1 addition & 0 deletions test/e2e/suite/command/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ var _ = Describe("ORAS beginners:", func() {
It("should show help description with feature flags", func() {
out := ORAS("push", "--help").MatchKeyWords(ExampleDesc).Exec().Out
gomega.Expect(out).Should(gbytes.Say("--image-spec string\\s+%s", regexp.QuoteMeta(feature.Preview.Mark)))
gomega.Expect(out).Should(gbytes.Say("--oci-layout-path string\\s+%s", regexp.QuoteMeta(feature.Experimental.Mark)))
})

It("should not show --verbose in help doc", func() {
Expand Down

0 comments on commit 52800e0

Please sign in to comment.