Skip to content

Commit

Permalink
resolved comments
Browse files Browse the repository at this point in the history
Signed-off-by: Xiaoxuan Wang <xiaoxuanwang@microsoft.com>
  • Loading branch information
Xiaoxuan Wang committed Oct 10, 2024
1 parent 49091a2 commit 66249a8
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 61 deletions.
2 changes: 1 addition & 1 deletion cmd/oras/internal/display/content/manifest_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type manifestIndexCreate struct {
// OnContentCreated is called after index content is created.
func (h *manifestIndexCreate) OnContentCreated(manifest []byte) error {
out := h.stdout
if h.outputPath != "-" && h.outputPath != "" {
if h.outputPath != "" && h.outputPath != "-" {
f, err := os.Create(h.outputPath)
if err != nil {
return fmt.Errorf("failed to open %q: %w", h.outputPath, err)

Check warning on line 39 in cmd/oras/internal/display/content/manifest_index.go

View check run for this annotation

Codecov / codecov/patch

cmd/oras/internal/display/content/manifest_index.go#L39

Added line #L39 was not covered by tests
Expand Down
7 changes: 1 addition & 6 deletions cmd/oras/internal/display/metadata/discard.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (discard) OnCompleted(ocispec.Descriptor) error {
}

// OnIndexPacked implements ManifestIndexCreateHandler.
func (discard) OnIndexPacked(string) error {
func (discard) OnIndexPacked(ocispec.Descriptor) error {
return nil
}

Expand All @@ -66,8 +66,3 @@ func (discard) OnManifestAdded(string, digest.Digest) error {
func (discard) OnIndexMerged(string, digest.Digest) error {
return nil

Check warning on line 67 in cmd/oras/internal/display/metadata/discard.go

View check run for this annotation

Codecov / codecov/patch

cmd/oras/internal/display/metadata/discard.go#L66-L67

Added lines #L66 - L67 were not covered by tests
}

// OnIndexUpdated implements ManifestIndexUpdateHandler.
func (discard) OnIndexUpdated(digest.Digest) error {
return nil
}
14 changes: 8 additions & 6 deletions cmd/oras/internal/display/metadata/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,23 +79,25 @@ type ManifestPushHandler interface {
TaggedHandler
}

type manifestPackHandler interface {
OnIndexPacked(desc ocispec.Descriptor) error
OnIndexPushed(path string) error
OnCompleted(desc ocispec.Descriptor) error
}

// ManifestIndexCreateHandler handles metadata output for index create events.
type ManifestIndexCreateHandler interface {
TaggedHandler
OnIndexPacked(shortDigest string) error
OnIndexPushed(path string) error
OnCompleted(desc ocispec.Descriptor) error
manifestPackHandler
}

// ManifestIndexUpdateHandler handles metadata output for index update events.
type ManifestIndexUpdateHandler interface {
TaggedHandler
manifestPackHandler
OnManifestRemoved(digest digest.Digest) error
OnManifestAdded(manifestRef string, digest digest.Digest) error
OnIndexMerged(indexRef string, digest digest.Digest) error
OnIndexUpdated(digest digest.Digest) error
OnIndexPushed(path string) error
OnCompleted(desc ocispec.Descriptor) error
}

// CopyHandler handles metadata output for cp events.
Expand Down
9 changes: 5 additions & 4 deletions cmd/oras/internal/display/metadata/text/manifest_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"oras.land/oras/cmd/oras/internal/display/metadata"
"oras.land/oras/cmd/oras/internal/output"
"oras.land/oras/internal/contentutil"
"oras.land/oras/internal/descriptor"
)

// ManifestIndexCreateHandler handles text metadata output for index create events.
Expand All @@ -36,8 +37,8 @@ func NewManifestIndexCreateHandler(printer *output.Printer) metadata.ManifestInd
}

// OnIndexPacked implements metadata.ManifestIndexCreateHandler.
func (h *ManifestIndexCreateHandler) OnIndexPacked(shortDigest string) error {
return h.printer.Println("Packed", shortDigest, ocispec.MediaTypeImageIndex)
func (h *ManifestIndexCreateHandler) OnIndexPacked(desc ocispec.Descriptor) error {
return h.printer.Println("Packed", descriptor.ShortDigest(desc), ocispec.MediaTypeImageIndex)
}

// OnIndexPushed implements metadata.ManifestIndexCreateHandler.
Expand Down Expand Up @@ -88,8 +89,8 @@ func (miuh ManifestIndexUpdateHandler) OnIndexMerged(ref string, digest digest.D
}

// OnIndexUpdated implements metadata.ManifestIndexUpdateHandler.
func (miuh ManifestIndexUpdateHandler) OnIndexUpdated(digest digest.Digest) error {
return miuh.printer.Println("Updated", digest)
func (miuh ManifestIndexUpdateHandler) OnIndexPacked(desc ocispec.Descriptor) error {
return miuh.printer.Println("Updated", desc.Digest)
}

// OnIndexPushed implements metadata.ManifestIndexUpdateHandler.
Expand Down
18 changes: 4 additions & 14 deletions cmd/oras/internal/display/status/discard.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,13 @@ func (DiscardHandler) OnNodeSkipped(desc ocispec.Descriptor) error {
return nil
}

// OnSourceManifestFetching implements ManifestReferenceFetchHandler.
func (DiscardHandler) OnManifestFetching(string) error {
// OnFetching implements referenceFetchHandler.
func (DiscardHandler) OnFetching(string) error {
return nil
}

// OnSourceManifestFetched implements ManifestReferenceFetchHandler.
func (DiscardHandler) OnManifestFetched(string, digest.Digest) error {
// OnFetched implements referenceFetchHandler.
func (DiscardHandler) OnFetched(string, ocispec.Descriptor) error {
return nil
}

Expand All @@ -110,16 +110,6 @@ func (DiscardHandler) OnManifestAdded(string, digest.Digest) error {
return nil

Check warning on line 110 in cmd/oras/internal/display/status/discard.go

View check run for this annotation

Codecov / codecov/patch

cmd/oras/internal/display/status/discard.go#L109-L110

Added lines #L109 - L110 were not covered by tests
}

// OnIndexFetching implements ManifestIndexUpdateHandler.
func (DiscardHandler) OnIndexFetching(string) error {
return nil
}

// OnIndexFetched implements ManifestIndexUpdateHandler.
func (DiscardHandler) OnIndexFetched(string, digest.Digest) error {
return nil
}

// OnIndexMerged implements ManifestIndexUpdateHandler.
func (DiscardHandler) OnIndexMerged(string, digest.Digest) error {
return nil

Check warning on line 115 in cmd/oras/internal/display/status/discard.go

View check run for this annotation

Codecov / codecov/patch

cmd/oras/internal/display/status/discard.go#L114-L115

Added lines #L114 - L115 were not covered by tests
Expand Down
17 changes: 6 additions & 11 deletions cmd/oras/internal/display/status/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package status
import (
"context"

"github.com/opencontainers/go-digest"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"oras.land/oras-go/v2"
)
Expand Down Expand Up @@ -64,20 +63,16 @@ type CopyHandler interface {
OnMounted(ctx context.Context, desc ocispec.Descriptor) error
}

// ManifestReferenceFetchHandler handles status output for manifest reference fetch events.
type ManifestReferenceFetchHandler interface {
OnManifestFetching(manifestRef string) error
OnManifestFetched(manifestRef string, digest digest.Digest) error
// referenceFetchHandler handles status output for reference fetch events.
type referenceFetchHandler interface {
OnFetching(manifestRef string) error
OnFetched(manifestRef string, desc ocispec.Descriptor) error
}

// ManifestIndexCreateHandler handles status output for manifest index create command.
type ManifestIndexCreateHandler interface {
ManifestReferenceFetchHandler
referenceFetchHandler
}

// ManifestIndexUpdateHandler handles status output for manifest index update command.
type ManifestIndexUpdateHandler interface {
ManifestReferenceFetchHandler
OnIndexFetching(indexRef string) error
OnIndexFetched(indexRef string, digest digest.Digest) error
}
type ManifestIndexUpdateHandler ManifestIndexCreateHandler
18 changes: 9 additions & 9 deletions cmd/oras/internal/display/status/text.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,13 @@ type TextManifestIndexCreateHandler struct {
printer *output.Printer
}

// OnSourceManifestFetching implements ManifestIndexCreateHandler.
func (mich TextManifestIndexCreateHandler) OnManifestFetching(source string) error {
// OnFetching implements ManifestIndexCreateHandler.
func (mich TextManifestIndexCreateHandler) OnFetching(source string) error {
return mich.printer.Println(IndexPromptFetching, source)
}

// OnSourceManifestFetched implements ManifestIndexCreateHandler.
func (mich TextManifestIndexCreateHandler) OnManifestFetched(source string, _ digest.Digest) error {
// OnFetched implements ManifestIndexCreateHandler.
func (mich TextManifestIndexCreateHandler) OnFetched(source string, _ ocispec.Descriptor) error {
return mich.printer.Println(IndexPromptFetched, source)
}

Expand Down Expand Up @@ -223,17 +223,17 @@ func (miuh TextManifestIndexUpdateHandler) OnIndexFetched(indexRef string, diges
return miuh.printer.Println(IndexPromptFetched, digest, indexRef)

Check warning on line 223 in cmd/oras/internal/display/status/text.go

View check run for this annotation

Codecov / codecov/patch

cmd/oras/internal/display/status/text.go#L223

Added line #L223 was not covered by tests
}

// OnManifestFetching implements ManifestIndexUpdateHandler.
func (miuh TextManifestIndexUpdateHandler) OnManifestFetching(ref string) error {
// OnFetching implements ManifestIndexUpdateHandler.
func (miuh TextManifestIndexUpdateHandler) OnFetching(ref string) error {
return miuh.printer.Println(IndexPromptFetching, ref)
}

// OnManifestFetched implements ManifestIndexUpdateHandler.
func (miuh TextManifestIndexUpdateHandler) OnManifestFetched(ref string, digest digest.Digest) error {
// OnFetched implements ManifestIndexUpdateHandler.
func (miuh TextManifestIndexUpdateHandler) OnFetched(ref string, desc ocispec.Descriptor) error {
if contentutil.IsDigest(ref) {
return miuh.printer.Println(IndexPromptFetched, ref)
}
return miuh.printer.Println(IndexPromptFetched, digest, ref)
return miuh.printer.Println(IndexPromptFetched, desc.Digest, ref)
}

// NewTextManifestIndexUpdateHandler returns a new handler for manifest index create command.
Expand Down
6 changes: 3 additions & 3 deletions cmd/oras/root/manifest/index/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func createIndex(cmd *cobra.Command, opts createOptions) error {
return err
}
desc := content.NewDescriptorFromBytes(ocispec.MediaTypeImageIndex, indexBytes)
if err := displayMetadata.OnIndexPacked(descriptor.ShortDigest(desc)); err != nil {
if err := displayMetadata.OnIndexPacked(desc); err != nil {
return err

Check warning on line 132 in cmd/oras/root/manifest/index/create.go

View check run for this annotation

Codecov / codecov/patch

cmd/oras/root/manifest/index/create.go#L132

Added line #L132 was not covered by tests
}
if err := displayContent.OnContentCreated(indexBytes); err != nil {
Expand All @@ -145,7 +145,7 @@ func createIndex(cmd *cobra.Command, opts createOptions) error {
func fetchSourceManifests(ctx context.Context, displayStatus status.ManifestIndexCreateHandler, target oras.ReadOnlyTarget, sources []string) ([]ocispec.Descriptor, error) {
resolved := []ocispec.Descriptor{}
for _, source := range sources {
if err := displayStatus.OnManifestFetching(source); err != nil {
if err := displayStatus.OnFetching(source); err != nil {
return nil, err

Check warning on line 149 in cmd/oras/root/manifest/index/create.go

View check run for this annotation

Codecov / codecov/patch

cmd/oras/root/manifest/index/create.go#L149

Added line #L149 was not covered by tests
}
desc, content, err := oras.FetchBytes(ctx, target, source, oras.DefaultFetchBytesOptions)
Expand All @@ -155,7 +155,7 @@ func fetchSourceManifests(ctx context.Context, displayStatus status.ManifestInde
if !descriptor.IsManifest(desc) {
return nil, fmt.Errorf("%s is not a manifest", source)
}
if err := displayStatus.OnManifestFetched(source, desc.Digest); err != nil {
if err := displayStatus.OnFetched(source, desc); err != nil {
return nil, err

Check warning on line 159 in cmd/oras/root/manifest/index/create.go

View check run for this annotation

Codecov / codecov/patch

cmd/oras/root/manifest/index/create.go#L159

Added line #L159 was not covered by tests
}
desc = descriptor.Plain(desc)
Expand Down
14 changes: 7 additions & 7 deletions cmd/oras/root/manifest/index/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func updateIndex(cmd *cobra.Command, opts updateOptions) error {
return err
}
desc := content.NewDescriptorFromBytes(index.MediaType, indexBytes)
if err := displayMetadata.OnIndexUpdated(desc.Digest); err != nil {
if err := displayMetadata.OnIndexPacked(desc); err != nil {
return err

Check warning on line 144 in cmd/oras/root/manifest/index/update.go

View check run for this annotation

Codecov / codecov/patch

cmd/oras/root/manifest/index/update.go#L144

Added line #L144 was not covered by tests
}
path := getPushPath(opts.RawReference, opts.Type, opts.Reference, opts.Path)
Expand All @@ -156,7 +156,7 @@ func updateIndex(cmd *cobra.Command, opts updateOptions) error {
}

func fetchIndex(ctx context.Context, handler status.ManifestIndexUpdateHandler, target oras.ReadOnlyTarget, reference string) (ocispec.Index, error) {
if err := handler.OnIndexFetching(reference); err != nil {
if err := handler.OnFetching(reference); err != nil {
return ocispec.Index{}, err

Check warning on line 160 in cmd/oras/root/manifest/index/update.go

View check run for this annotation

Codecov / codecov/patch

cmd/oras/root/manifest/index/update.go#L160

Added line #L160 was not covered by tests
}
desc, content, err := oras.FetchBytes(ctx, target, reference, oras.DefaultFetchBytesOptions)
Expand All @@ -166,7 +166,7 @@ func fetchIndex(ctx context.Context, handler status.ManifestIndexUpdateHandler,
if !descriptor.IsIndex(desc) {
return ocispec.Index{}, fmt.Errorf("%s is not an index", reference)
}
if err := handler.OnIndexFetched(reference, desc.Digest); err != nil {
if err := handler.OnFetched(reference, desc); err != nil {
return ocispec.Index{}, err

Check warning on line 170 in cmd/oras/root/manifest/index/update.go

View check run for this annotation

Codecov / codecov/patch

cmd/oras/root/manifest/index/update.go#L170

Added line #L170 was not covered by tests
}
var index ocispec.Index
Expand All @@ -178,7 +178,7 @@ func fetchIndex(ctx context.Context, handler status.ManifestIndexUpdateHandler,

func addManifests(ctx context.Context, displayStatus status.ManifestIndexUpdateHandler, displayMetadata metadata.ManifestIndexUpdateHandler, manifests []ocispec.Descriptor, target oras.ReadOnlyTarget, addArguments []string) ([]ocispec.Descriptor, error) {
for _, manifestRef := range addArguments {
if err := displayStatus.OnManifestFetching(manifestRef); err != nil {
if err := displayStatus.OnFetching(manifestRef); err != nil {
return nil, err

Check warning on line 182 in cmd/oras/root/manifest/index/update.go

View check run for this annotation

Codecov / codecov/patch

cmd/oras/root/manifest/index/update.go#L182

Added line #L182 was not covered by tests
}
desc, content, err := oras.FetchBytes(ctx, target, manifestRef, oras.DefaultFetchBytesOptions)
Expand All @@ -188,7 +188,7 @@ func addManifests(ctx context.Context, displayStatus status.ManifestIndexUpdateH
if !descriptor.IsManifest(desc) {
return nil, fmt.Errorf("%s is not a manifest", manifestRef)
}
if err := displayStatus.OnManifestFetched(manifestRef, desc.Digest); err != nil {
if err := displayStatus.OnFetched(manifestRef, desc); err != nil {
return nil, err

Check warning on line 192 in cmd/oras/root/manifest/index/update.go

View check run for this annotation

Codecov / codecov/patch

cmd/oras/root/manifest/index/update.go#L192

Added line #L192 was not covered by tests
}
if descriptor.IsImageManifest(desc) {
Expand All @@ -207,7 +207,7 @@ func addManifests(ctx context.Context, displayStatus status.ManifestIndexUpdateH

func mergeIndexes(ctx context.Context, displayStatus status.ManifestIndexUpdateHandler, displayMetadata metadata.ManifestIndexUpdateHandler, manifests []ocispec.Descriptor, target oras.ReadOnlyTarget, mergeArguments []string) ([]ocispec.Descriptor, error) {
for _, indexRef := range mergeArguments {
if err := displayStatus.OnIndexFetching(indexRef); err != nil {
if err := displayStatus.OnFetching(indexRef); err != nil {
return nil, err

Check warning on line 211 in cmd/oras/root/manifest/index/update.go

View check run for this annotation

Codecov / codecov/patch

cmd/oras/root/manifest/index/update.go#L211

Added line #L211 was not covered by tests
}
desc, content, err := oras.FetchBytes(ctx, target, indexRef, oras.DefaultFetchBytesOptions)
Expand All @@ -217,7 +217,7 @@ func mergeIndexes(ctx context.Context, displayStatus status.ManifestIndexUpdateH
if !descriptor.IsIndex(desc) {
return nil, fmt.Errorf("%s is not an index", indexRef)
}
if err := displayStatus.OnIndexFetched(indexRef, desc.Digest); err != nil {
if err := displayStatus.OnFetched(indexRef, desc); err != nil {
return nil, err

Check warning on line 221 in cmd/oras/root/manifest/index/update.go

View check run for this annotation

Codecov / codecov/patch

cmd/oras/root/manifest/index/update.go#L221

Added line #L221 was not covered by tests
}
var index ocispec.Index
Expand Down

0 comments on commit 66249a8

Please sign in to comment.