From 5510cbf7fa70288b29a08b77a35d05c2ead70940 Mon Sep 17 00:00:00 2001 From: Xiaoxuan Wang Date: Fri, 29 Nov 2024 15:51:04 +0800 Subject: [PATCH 01/15] created status handler for manifest push Signed-off-by: Xiaoxuan Wang --- cmd/oras/internal/display/handler.go | 4 +-- cmd/oras/internal/display/status/interface.go | 8 +++++ cmd/oras/internal/display/status/text.go | 32 +++++++++++++++++++ cmd/oras/internal/display/status/utils.go | 1 + cmd/oras/root/manifest/push.go | 15 +++++---- 5 files changed, 52 insertions(+), 8 deletions(-) diff --git a/cmd/oras/internal/display/handler.go b/cmd/oras/internal/display/handler.go index de84a1723..c1b469c9a 100644 --- a/cmd/oras/internal/display/handler.go +++ b/cmd/oras/internal/display/handler.go @@ -170,8 +170,8 @@ func NewTagHandler(printer *output.Printer, target option.Target) metadata.TagHa } // NewManifestPushHandler returns a manifest push handler. -func NewManifestPushHandler(printer *output.Printer) metadata.ManifestPushHandler { - return text.NewManifestPushHandler(printer) +func NewManifestPushHandler(printer *output.Printer) (status.ManifestPushHandler, metadata.ManifestPushHandler) { + return status.NewTextManifestPushHandler(printer), text.NewManifestPushHandler(printer) } // NewManifestIndexCreateHandler returns status, metadata and content handlers for index create command. diff --git a/cmd/oras/internal/display/status/interface.go b/cmd/oras/internal/display/status/interface.go index 0a918e42f..45251d264 100644 --- a/cmd/oras/internal/display/status/interface.go +++ b/cmd/oras/internal/display/status/interface.go @@ -64,6 +64,14 @@ type CopyHandler interface { OnMounted(ctx context.Context, desc ocispec.Descriptor) error } +// ManifestPushHandler handles status output for manifest push command. +type ManifestPushHandler interface { + OnManifestExists(desc ocispec.Descriptor) error + OnManifestUploading(desc ocispec.Descriptor) error + OnManifestUploaded(desc ocispec.Descriptor) error + OnManifestPushed(ref string) error +} + // ManifestIndexCreateHandler handles status output for manifest index create command. type ManifestIndexCreateHandler interface { OnFetching(manifestRef string) error diff --git a/cmd/oras/internal/display/status/text.go b/cmd/oras/internal/display/status/text.go index 76b54f09d..9e6d81aac 100644 --- a/cmd/oras/internal/display/status/text.go +++ b/cmd/oras/internal/display/status/text.go @@ -183,6 +183,38 @@ func (ch *TextCopyHandler) OnMounted(_ context.Context, desc ocispec.Descriptor) return ch.printer.PrintStatus(desc, copyPromptMounted) } +// TextManifestPushHandler handles text status output for manifest push events. +type TextManifestPushHandler struct { + printer *output.Printer +} + +// NewTextManifestPushHandler returns a new handler for manifest push command. +func NewTextManifestPushHandler(printer *output.Printer) ManifestPushHandler { + tmich := TextManifestPushHandler{ + printer: printer, + } + return &tmich +} + +func (mph *TextManifestPushHandler) OnManifestExists(desc ocispec.Descriptor) error { + name, _ := descriptor.GetTitleOrMediaType(desc) + return mph.printer.Println(PushPromptExists, descriptor.ShortDigest(desc), name) +} + +func (mph *TextManifestPushHandler) OnManifestUploading(desc ocispec.Descriptor) error { + name, _ := descriptor.GetTitleOrMediaType(desc) + return mph.printer.Println(PushPromptUploading, descriptor.ShortDigest(desc), name) +} + +func (mph *TextManifestPushHandler) OnManifestUploaded(desc ocispec.Descriptor) error { + name, _ := descriptor.GetTitleOrMediaType(desc) + return mph.printer.Println(PushPromptUploaded, descriptor.ShortDigest(desc), name) +} + +func (mph *TextManifestPushHandler) OnManifestPushed(ref string) error { + return mph.printer.Println(PushPromptPushed, ref) +} + // TextManifestIndexCreateHandler handles text status output for manifest index create events. type TextManifestIndexCreateHandler struct { printer *output.Printer diff --git a/cmd/oras/internal/display/status/utils.go b/cmd/oras/internal/display/status/utils.go index 79662a72f..26c65ab99 100644 --- a/cmd/oras/internal/display/status/utils.go +++ b/cmd/oras/internal/display/status/utils.go @@ -37,6 +37,7 @@ const ( PushPromptUploading = "Uploading" PushPromptSkipped = "Skipped " PushPromptExists = "Exists " + PushPromptPushed = "Pushed " ) // Prompts for cp events. diff --git a/cmd/oras/root/manifest/push.go b/cmd/oras/root/manifest/push.go index 78f61ece8..9be85e3b0 100644 --- a/cmd/oras/root/manifest/push.go +++ b/cmd/oras/root/manifest/push.go @@ -145,6 +145,8 @@ func pushManifest(cmd *cobra.Command, opts pushOptions) error { } } + displayStatus, displayMetadata := display.NewManifestPushHandler(opts.Printer) + // prepare manifest descriptor desc := content.NewDescriptorFromBytes(mediaType, contentBytes) @@ -157,17 +159,17 @@ func pushManifest(cmd *cobra.Command, opts pushOptions) error { return err } if match { - if err := opts.PrintStatus(desc, "Exists"); err != nil { + if err := displayStatus.OnManifestExists(desc); err != nil { return err } } else { - if err = opts.PrintStatus(desc, "Uploading"); err != nil { + if err = displayStatus.OnManifestUploading(desc); err != nil { return err } if _, err := oras.TagBytes(ctx, target, mediaType, contentBytes, ref); err != nil { return err } - if err = opts.PrintStatus(desc, "Uploaded "); err != nil { + if err = displayStatus.OnManifestUploaded(desc); err != nil { return err } } @@ -188,10 +190,11 @@ func pushManifest(cmd *cobra.Command, opts pushOptions) error { } return opts.Output(os.Stdout, descJSON) } - _ = opts.Println("Pushed", opts.AnnotatedReference()) + if err := displayStatus.OnManifestPushed(opts.AnnotatedReference()); err != nil { + return err + } if len(opts.extraRefs) != 0 { - handler := display.NewManifestPushHandler(opts.Printer) - tagListener := listener.NewTaggedListener(target, handler.OnTagged) + tagListener := listener.NewTaggedListener(target, displayMetadata.OnTagged) if _, err = oras.TagBytesN(ctx, tagListener, mediaType, contentBytes, opts.extraRefs, tagBytesNOpts); err != nil { return err } From 7bd8575c173c02bdb6eb2ad13d623df37dc53fae Mon Sep 17 00:00:00 2001 From: Xiaoxuan Wang Date: Fri, 29 Nov 2024 16:28:25 +0800 Subject: [PATCH 02/15] refactor: add handlers to manifest push Signed-off-by: Xiaoxuan Wang --- cmd/oras/internal/display/handler.go | 5 ++++- .../internal/display/metadata/interface.go | 1 + .../display/metadata/text/manifest_push.go | 5 +++++ cmd/oras/internal/display/status/discard.go | 20 +++++++++++++++++++ cmd/oras/root/manifest/push.go | 6 ++---- 5 files changed, 32 insertions(+), 5 deletions(-) diff --git a/cmd/oras/internal/display/handler.go b/cmd/oras/internal/display/handler.go index c1b469c9a..731a0f600 100644 --- a/cmd/oras/internal/display/handler.go +++ b/cmd/oras/internal/display/handler.go @@ -170,7 +170,10 @@ func NewTagHandler(printer *output.Printer, target option.Target) metadata.TagHa } // NewManifestPushHandler returns a manifest push handler. -func NewManifestPushHandler(printer *output.Printer) (status.ManifestPushHandler, metadata.ManifestPushHandler) { +func NewManifestPushHandler(printer *output.Printer, outputDescriptor bool, pretty bool) (status.ManifestPushHandler, metadata.ManifestPushHandler) { + if outputDescriptor { + return status.NewDiscardHandler(), metadata.NewDiscardHandler() + } return status.NewTextManifestPushHandler(printer), text.NewManifestPushHandler(printer) } diff --git a/cmd/oras/internal/display/metadata/interface.go b/cmd/oras/internal/display/metadata/interface.go index 32b18f2bf..786dfbd76 100644 --- a/cmd/oras/internal/display/metadata/interface.go +++ b/cmd/oras/internal/display/metadata/interface.go @@ -76,6 +76,7 @@ type TagHandler interface { // ManifestPushHandler handles metadata output for manifest push events. type ManifestPushHandler interface { TaggedHandler + OnCompleted(desc ocispec.Descriptor) error } // ManifestIndexCreateHandler handles metadata output for index create events. diff --git a/cmd/oras/internal/display/metadata/text/manifest_push.go b/cmd/oras/internal/display/metadata/text/manifest_push.go index 743ba7ee2..f6246a118 100644 --- a/cmd/oras/internal/display/metadata/text/manifest_push.go +++ b/cmd/oras/internal/display/metadata/text/manifest_push.go @@ -37,3 +37,8 @@ func NewManifestPushHandler(printer *output.Printer) metadata.ManifestPushHandle func (h *ManifestPushHandler) OnTagged(_ ocispec.Descriptor, tag string) error { return h.printer.Println("Tagged", tag) } + +// OnCompleted implements metadata.ManifestPushHandler. +func (h *ManifestPushHandler) OnCompleted(desc ocispec.Descriptor) error { + return h.printer.Println("Digest:", desc.Digest) +} diff --git a/cmd/oras/internal/display/status/discard.go b/cmd/oras/internal/display/status/discard.go index 2bdc09ff4..b86b119c8 100644 --- a/cmd/oras/internal/display/status/discard.go +++ b/cmd/oras/internal/display/status/discard.go @@ -100,6 +100,26 @@ func (DiscardHandler) OnFetched(string, ocispec.Descriptor) error { return nil } +// OnManifestExists implements ManifestPushHandler. +func (DiscardHandler) OnManifestExists(desc ocispec.Descriptor) error { + return nil +} + +// OnManifestUploading implements ManifestPushHandler. +func (DiscardHandler) OnManifestUploading(desc ocispec.Descriptor) error { + return nil +} + +// OnManifestUploaded implements ManifestPushHandler. +func (DiscardHandler) OnManifestUploaded(desc ocispec.Descriptor) error { + return nil +} + +// OnManifestPushed implements ManifestPushHandler. +func (DiscardHandler) OnManifestPushed(ref string) error { + return nil +} + // OnManifestRemoved implements ManifestIndexUpdateHandler. func (DiscardHandler) OnManifestRemoved(digest.Digest) error { return nil diff --git a/cmd/oras/root/manifest/push.go b/cmd/oras/root/manifest/push.go index 9be85e3b0..e5de6f56c 100644 --- a/cmd/oras/root/manifest/push.go +++ b/cmd/oras/root/manifest/push.go @@ -145,7 +145,7 @@ func pushManifest(cmd *cobra.Command, opts pushOptions) error { } } - displayStatus, displayMetadata := display.NewManifestPushHandler(opts.Printer) + displayStatus, displayMetadata := display.NewManifestPushHandler(opts.Printer, opts.OutputDescriptor, opts.Pretty.Pretty) // prepare manifest descriptor desc := content.NewDescriptorFromBytes(mediaType, contentBytes) @@ -200,9 +200,7 @@ func pushManifest(cmd *cobra.Command, opts pushOptions) error { } } - _ = opts.Println("Digest:", desc.Digest) - - return nil + return displayMetadata.OnCompleted(desc) } // matchDigest checks whether the manifest's digest matches to it in the remote From 47de1f76d270ea17b1d8305eac595703b101ef38 Mon Sep 17 00:00:00 2001 From: Xiaoxuan Wang Date: Tue, 3 Dec 2024 09:58:11 +0800 Subject: [PATCH 03/15] reverted verbose flag change Signed-off-by: Xiaoxuan Wang --- cmd/oras/internal/display/status/text.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/cmd/oras/internal/display/status/text.go b/cmd/oras/internal/display/status/text.go index 9e6d81aac..cf17281b4 100644 --- a/cmd/oras/internal/display/status/text.go +++ b/cmd/oras/internal/display/status/text.go @@ -197,18 +197,15 @@ func NewTextManifestPushHandler(printer *output.Printer) ManifestPushHandler { } func (mph *TextManifestPushHandler) OnManifestExists(desc ocispec.Descriptor) error { - name, _ := descriptor.GetTitleOrMediaType(desc) - return mph.printer.Println(PushPromptExists, descriptor.ShortDigest(desc), name) + return mph.printer.PrintStatus(desc, PushPromptExists) } func (mph *TextManifestPushHandler) OnManifestUploading(desc ocispec.Descriptor) error { - name, _ := descriptor.GetTitleOrMediaType(desc) - return mph.printer.Println(PushPromptUploading, descriptor.ShortDigest(desc), name) + return mph.printer.PrintStatus(desc, PushPromptUploading) } func (mph *TextManifestPushHandler) OnManifestUploaded(desc ocispec.Descriptor) error { - name, _ := descriptor.GetTitleOrMediaType(desc) - return mph.printer.Println(PushPromptUploaded, descriptor.ShortDigest(desc), name) + return mph.printer.PrintStatus(desc, PushPromptUploaded) } func (mph *TextManifestPushHandler) OnManifestPushed(ref string) error { From 591931aa107091364eab4c7e53fe5bc34cebb976 Mon Sep 17 00:00:00 2001 From: Xiaoxuan Wang Date: Tue, 3 Dec 2024 10:56:59 +0800 Subject: [PATCH 04/15] increase test coverage Signed-off-by: Xiaoxuan Wang --- cmd/oras/internal/display/status/discard_test.go | 7 +++++++ cmd/oras/internal/display/status/text_test.go | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/cmd/oras/internal/display/status/discard_test.go b/cmd/oras/internal/display/status/discard_test.go index bf5a71363..0de7c8c5a 100644 --- a/cmd/oras/internal/display/status/discard_test.go +++ b/cmd/oras/internal/display/status/discard_test.go @@ -21,6 +21,13 @@ import ( v1 "github.com/opencontainers/image-spec/specs-go/v1" ) +func TestDiscardHandler_OnManifestPushed(t *testing.T) { + testDiscard := NewDiscardHandler() + if err := testDiscard.OnManifestPushed("test"); err != nil { + t.Errorf("DiscardHandler.OnIndexMerged() error = %v, wantErr nil", err) + } +} + func TestDiscardHandler_OnManifestRemoved(t *testing.T) { testDiscard := NewDiscardHandler() if err := testDiscard.OnManifestRemoved("sha256:44136fa355b3678a1146ad16f7e8649e94fb4fc21fe77e8310c060f61caaff8a"); err != nil { diff --git a/cmd/oras/internal/display/status/text_test.go b/cmd/oras/internal/display/status/text_test.go index 85d354771..32a42e3d4 100644 --- a/cmd/oras/internal/display/status/text_test.go +++ b/cmd/oras/internal/display/status/text_test.go @@ -194,6 +194,14 @@ func TestTextPushHandler_PreCopy(t *testing.T) { validatePrinted(t, "Uploading 0b442c23c1dd oci-image") } +func TestTextManifestPushHandler_OnManifestExists(t *testing.T) { + mph := NewTextManifestPushHandler(printer) + if mph.OnManifestExists(ocispec.Descriptor{}) != nil { + t.Error("OnManifestExists() should not return an error") + } + validatePrinted(t, "") +} + func TestTextManifestIndexUpdateHandler_OnManifestAdded(t *testing.T) { tests := []struct { name string From 5154cf6057480627f4de3ba108d7cf439a685aa5 Mon Sep 17 00:00:00 2001 From: Xiaoxuan Wang Date: Tue, 3 Dec 2024 11:20:48 +0800 Subject: [PATCH 05/15] change unit test Signed-off-by: Xiaoxuan Wang --- cmd/oras/internal/display/status/text_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/cmd/oras/internal/display/status/text_test.go b/cmd/oras/internal/display/status/text_test.go index 32a42e3d4..cb6a245de 100644 --- a/cmd/oras/internal/display/status/text_test.go +++ b/cmd/oras/internal/display/status/text_test.go @@ -199,7 +199,6 @@ func TestTextManifestPushHandler_OnManifestExists(t *testing.T) { if mph.OnManifestExists(ocispec.Descriptor{}) != nil { t.Error("OnManifestExists() should not return an error") } - validatePrinted(t, "") } func TestTextManifestIndexUpdateHandler_OnManifestAdded(t *testing.T) { From 1e4e94ced6ae4853bbe9908fd4ec0d4574480a80 Mon Sep 17 00:00:00 2001 From: Xiaoxuan Wang Date: Tue, 3 Dec 2024 11:25:00 +0800 Subject: [PATCH 06/15] increase coverage Signed-off-by: Xiaoxuan Wang --- cmd/oras/internal/display/status/discard_test.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/cmd/oras/internal/display/status/discard_test.go b/cmd/oras/internal/display/status/discard_test.go index 0de7c8c5a..11b6582f9 100644 --- a/cmd/oras/internal/display/status/discard_test.go +++ b/cmd/oras/internal/display/status/discard_test.go @@ -28,6 +28,13 @@ func TestDiscardHandler_OnManifestPushed(t *testing.T) { } } +func TestDiscardHandler_OnManifestExists(t *testing.T) { + testDiscard := NewDiscardHandler() + if err := testDiscard.OnManifestExists(v1.Descriptor{}); err != nil { + t.Errorf("DiscardHandler.OnIndexExists() error = %v, wantErr nil", err) + } +} + func TestDiscardHandler_OnManifestRemoved(t *testing.T) { testDiscard := NewDiscardHandler() if err := testDiscard.OnManifestRemoved("sha256:44136fa355b3678a1146ad16f7e8649e94fb4fc21fe77e8310c060f61caaff8a"); err != nil { From 2f1023387580f03eebca86c2679a4286ec2ae8d1 Mon Sep 17 00:00:00 2001 From: Xiaoxuan Wang Date: Wed, 4 Dec 2024 10:56:11 +0800 Subject: [PATCH 07/15] resolve some comments Signed-off-by: Xiaoxuan Wang --- cmd/oras/internal/display/handler.go | 4 ++-- .../display/metadata/text/manifest_push.go | 5 ++++- cmd/oras/internal/display/status/discard.go | 8 ++++---- .../internal/display/status/discard_test.go | 4 ++-- cmd/oras/internal/display/status/interface.go | 6 +++--- cmd/oras/internal/display/status/text.go | 19 ++++++++++--------- cmd/oras/internal/display/status/text_test.go | 6 +++--- cmd/oras/root/manifest/push.go | 10 +++++----- 8 files changed, 33 insertions(+), 29 deletions(-) diff --git a/cmd/oras/internal/display/handler.go b/cmd/oras/internal/display/handler.go index 731a0f600..4d80c9867 100644 --- a/cmd/oras/internal/display/handler.go +++ b/cmd/oras/internal/display/handler.go @@ -170,11 +170,11 @@ func NewTagHandler(printer *output.Printer, target option.Target) metadata.TagHa } // NewManifestPushHandler returns a manifest push handler. -func NewManifestPushHandler(printer *output.Printer, outputDescriptor bool, pretty bool) (status.ManifestPushHandler, metadata.ManifestPushHandler) { +func NewManifestPushHandler(printer *output.Printer, outputDescriptor bool, pretty bool, desc ocispec.Descriptor, target option.Target) (status.ManifestPushHandler, metadata.ManifestPushHandler) { if outputDescriptor { return status.NewDiscardHandler(), metadata.NewDiscardHandler() } - return status.NewTextManifestPushHandler(printer), text.NewManifestPushHandler(printer) + return status.NewTextManifestPushHandler(printer, desc), text.NewManifestPushHandler(printer, target) } // NewManifestIndexCreateHandler returns status, metadata and content handlers for index create command. diff --git a/cmd/oras/internal/display/metadata/text/manifest_push.go b/cmd/oras/internal/display/metadata/text/manifest_push.go index f6246a118..b8686da3d 100644 --- a/cmd/oras/internal/display/metadata/text/manifest_push.go +++ b/cmd/oras/internal/display/metadata/text/manifest_push.go @@ -18,18 +18,21 @@ package text import ( ocispec "github.com/opencontainers/image-spec/specs-go/v1" "oras.land/oras/cmd/oras/internal/display/metadata" + "oras.land/oras/cmd/oras/internal/option" "oras.land/oras/cmd/oras/internal/output" ) // ManifestPushHandler handles text metadata output for manifest push events. type ManifestPushHandler struct { printer *output.Printer + target option.Target } // NewManifestPushHandler returns a new handler for manifest push events. -func NewManifestPushHandler(printer *output.Printer) metadata.ManifestPushHandler { +func NewManifestPushHandler(printer *output.Printer, target option.Target) metadata.ManifestPushHandler { return &ManifestPushHandler{ printer: printer, + target: target, } } diff --git a/cmd/oras/internal/display/status/discard.go b/cmd/oras/internal/display/status/discard.go index b86b119c8..ab9bc1610 100644 --- a/cmd/oras/internal/display/status/discard.go +++ b/cmd/oras/internal/display/status/discard.go @@ -100,18 +100,18 @@ func (DiscardHandler) OnFetched(string, ocispec.Descriptor) error { return nil } -// OnManifestExists implements ManifestPushHandler. -func (DiscardHandler) OnManifestExists(desc ocispec.Descriptor) error { +// OnPushSkipped implements ManifestPushHandler. +func (DiscardHandler) OnPushSkipped() error { return nil } // OnManifestUploading implements ManifestPushHandler. -func (DiscardHandler) OnManifestUploading(desc ocispec.Descriptor) error { +func (DiscardHandler) OnManifestUploading() error { return nil } // OnManifestUploaded implements ManifestPushHandler. -func (DiscardHandler) OnManifestUploaded(desc ocispec.Descriptor) error { +func (DiscardHandler) OnManifestUploaded() error { return nil } diff --git a/cmd/oras/internal/display/status/discard_test.go b/cmd/oras/internal/display/status/discard_test.go index 11b6582f9..5df1a1c62 100644 --- a/cmd/oras/internal/display/status/discard_test.go +++ b/cmd/oras/internal/display/status/discard_test.go @@ -28,9 +28,9 @@ func TestDiscardHandler_OnManifestPushed(t *testing.T) { } } -func TestDiscardHandler_OnManifestExists(t *testing.T) { +func TestDiscardHandler_OnPushSkipped(t *testing.T) { testDiscard := NewDiscardHandler() - if err := testDiscard.OnManifestExists(v1.Descriptor{}); err != nil { + if err := testDiscard.OnPushSkipped(); err != nil { t.Errorf("DiscardHandler.OnIndexExists() error = %v, wantErr nil", err) } } diff --git a/cmd/oras/internal/display/status/interface.go b/cmd/oras/internal/display/status/interface.go index 45251d264..e5151a634 100644 --- a/cmd/oras/internal/display/status/interface.go +++ b/cmd/oras/internal/display/status/interface.go @@ -66,9 +66,9 @@ type CopyHandler interface { // ManifestPushHandler handles status output for manifest push command. type ManifestPushHandler interface { - OnManifestExists(desc ocispec.Descriptor) error - OnManifestUploading(desc ocispec.Descriptor) error - OnManifestUploaded(desc ocispec.Descriptor) error + OnPushSkipped() error + OnManifestUploading() error + OnManifestUploaded() error OnManifestPushed(ref string) error } diff --git a/cmd/oras/internal/display/status/text.go b/cmd/oras/internal/display/status/text.go index cf17281b4..3a2e60a99 100644 --- a/cmd/oras/internal/display/status/text.go +++ b/cmd/oras/internal/display/status/text.go @@ -185,27 +185,28 @@ func (ch *TextCopyHandler) OnMounted(_ context.Context, desc ocispec.Descriptor) // TextManifestPushHandler handles text status output for manifest push events. type TextManifestPushHandler struct { + desc ocispec.Descriptor printer *output.Printer } // NewTextManifestPushHandler returns a new handler for manifest push command. -func NewTextManifestPushHandler(printer *output.Printer) ManifestPushHandler { - tmich := TextManifestPushHandler{ +func NewTextManifestPushHandler(printer *output.Printer, desc ocispec.Descriptor) ManifestPushHandler { + return &TextManifestPushHandler{ + desc: desc, printer: printer, } - return &tmich } -func (mph *TextManifestPushHandler) OnManifestExists(desc ocispec.Descriptor) error { - return mph.printer.PrintStatus(desc, PushPromptExists) +func (mph *TextManifestPushHandler) OnPushSkipped() error { + return mph.printer.PrintStatus(mph.desc, PushPromptExists) } -func (mph *TextManifestPushHandler) OnManifestUploading(desc ocispec.Descriptor) error { - return mph.printer.PrintStatus(desc, PushPromptUploading) +func (mph *TextManifestPushHandler) OnManifestUploading() error { + return mph.printer.PrintStatus(mph.desc, PushPromptUploading) } -func (mph *TextManifestPushHandler) OnManifestUploaded(desc ocispec.Descriptor) error { - return mph.printer.PrintStatus(desc, PushPromptUploaded) +func (mph *TextManifestPushHandler) OnManifestUploaded() error { + return mph.printer.PrintStatus(mph.desc, PushPromptUploaded) } func (mph *TextManifestPushHandler) OnManifestPushed(ref string) error { diff --git a/cmd/oras/internal/display/status/text_test.go b/cmd/oras/internal/display/status/text_test.go index cb6a245de..407db3f63 100644 --- a/cmd/oras/internal/display/status/text_test.go +++ b/cmd/oras/internal/display/status/text_test.go @@ -194,9 +194,9 @@ func TestTextPushHandler_PreCopy(t *testing.T) { validatePrinted(t, "Uploading 0b442c23c1dd oci-image") } -func TestTextManifestPushHandler_OnManifestExists(t *testing.T) { - mph := NewTextManifestPushHandler(printer) - if mph.OnManifestExists(ocispec.Descriptor{}) != nil { +func TestTextManifestPushHandler_OnPushSkipped(t *testing.T) { + mph := NewTextManifestPushHandler(printer, ocispec.Descriptor{}) + if mph.OnPushSkipped() != nil { t.Error("OnManifestExists() should not return an error") } } diff --git a/cmd/oras/root/manifest/push.go b/cmd/oras/root/manifest/push.go index b9885677c..f6b63890c 100644 --- a/cmd/oras/root/manifest/push.go +++ b/cmd/oras/root/manifest/push.go @@ -147,11 +147,11 @@ func pushManifest(cmd *cobra.Command, opts pushOptions) error { } } - displayStatus, displayMetadata := display.NewManifestPushHandler(opts.Printer, opts.OutputDescriptor, opts.Pretty.Pretty) - // prepare manifest descriptor desc := content.NewDescriptorFromBytes(mediaType, contentBytes) + displayStatus, displayMetadata := display.NewManifestPushHandler(opts.Printer, opts.OutputDescriptor, opts.Pretty.Pretty, desc, opts.Target) + ref := opts.Reference if ref == "" { ref = desc.Digest.String() @@ -161,17 +161,17 @@ func pushManifest(cmd *cobra.Command, opts pushOptions) error { return err } if match { - if err := displayStatus.OnManifestExists(desc); err != nil { + if err := displayStatus.OnPushSkipped(); err != nil { return err } } else { - if err = displayStatus.OnManifestUploading(desc); err != nil { + if err = displayStatus.OnManifestUploading(); err != nil { return err } if _, err := oras.TagBytes(ctx, target, mediaType, contentBytes, ref); err != nil { return err } - if err = displayStatus.OnManifestUploaded(desc); err != nil { + if err = displayStatus.OnManifestUploaded(); err != nil { return err } } From 76d5bdb62e7e9bdcbe2748194cb4bed0d4491863 Mon Sep 17 00:00:00 2001 From: Xiaoxuan Wang Date: Thu, 5 Dec 2024 15:51:02 +0800 Subject: [PATCH 08/15] resolve comment Signed-off-by: Xiaoxuan Wang --- cmd/oras/internal/display/metadata/discard.go | 5 +++++ cmd/oras/internal/display/metadata/interface.go | 1 + cmd/oras/internal/display/metadata/text/manifest_push.go | 5 +++++ cmd/oras/internal/display/status/interface.go | 1 - cmd/oras/internal/display/status/text.go | 4 ---- cmd/oras/root/manifest/push.go | 2 +- 6 files changed, 12 insertions(+), 6 deletions(-) diff --git a/cmd/oras/internal/display/metadata/discard.go b/cmd/oras/internal/display/metadata/discard.go index d5a3d3e6d..f0eba312a 100644 --- a/cmd/oras/internal/display/metadata/discard.go +++ b/cmd/oras/internal/display/metadata/discard.go @@ -31,6 +31,11 @@ func (Discard) OnFetched(string, ocispec.Descriptor, []byte) error { return nil } +// OnManifestPushed implements ManifestPushHandler. +func (Discard) OnManifestPushed() error { + return nil +} + // OnTagged implements ManifestIndexCreateHandler. func (Discard) OnTagged(ocispec.Descriptor, string) error { return nil diff --git a/cmd/oras/internal/display/metadata/interface.go b/cmd/oras/internal/display/metadata/interface.go index 786dfbd76..5a82dc106 100644 --- a/cmd/oras/internal/display/metadata/interface.go +++ b/cmd/oras/internal/display/metadata/interface.go @@ -76,6 +76,7 @@ type TagHandler interface { // ManifestPushHandler handles metadata output for manifest push events. type ManifestPushHandler interface { TaggedHandler + OnManifestPushed() error OnCompleted(desc ocispec.Descriptor) error } diff --git a/cmd/oras/internal/display/metadata/text/manifest_push.go b/cmd/oras/internal/display/metadata/text/manifest_push.go index b8686da3d..4983efccf 100644 --- a/cmd/oras/internal/display/metadata/text/manifest_push.go +++ b/cmd/oras/internal/display/metadata/text/manifest_push.go @@ -41,6 +41,11 @@ func (h *ManifestPushHandler) OnTagged(_ ocispec.Descriptor, tag string) error { return h.printer.Println("Tagged", tag) } +// OnManifestPushed implements metadata.ManifestPushHandler. +func (h *ManifestPushHandler) OnManifestPushed() error { + return h.printer.Println("Pushed:", h.target.AnnotatedReference()) +} + // OnCompleted implements metadata.ManifestPushHandler. func (h *ManifestPushHandler) OnCompleted(desc ocispec.Descriptor) error { return h.printer.Println("Digest:", desc.Digest) diff --git a/cmd/oras/internal/display/status/interface.go b/cmd/oras/internal/display/status/interface.go index e5151a634..c7437ee49 100644 --- a/cmd/oras/internal/display/status/interface.go +++ b/cmd/oras/internal/display/status/interface.go @@ -69,7 +69,6 @@ type ManifestPushHandler interface { OnPushSkipped() error OnManifestUploading() error OnManifestUploaded() error - OnManifestPushed(ref string) error } // ManifestIndexCreateHandler handles status output for manifest index create command. diff --git a/cmd/oras/internal/display/status/text.go b/cmd/oras/internal/display/status/text.go index 3a2e60a99..4c86baa8b 100644 --- a/cmd/oras/internal/display/status/text.go +++ b/cmd/oras/internal/display/status/text.go @@ -209,10 +209,6 @@ func (mph *TextManifestPushHandler) OnManifestUploaded() error { return mph.printer.PrintStatus(mph.desc, PushPromptUploaded) } -func (mph *TextManifestPushHandler) OnManifestPushed(ref string) error { - return mph.printer.Println(PushPromptPushed, ref) -} - // TextManifestIndexCreateHandler handles text status output for manifest index create events. type TextManifestIndexCreateHandler struct { printer *output.Printer diff --git a/cmd/oras/root/manifest/push.go b/cmd/oras/root/manifest/push.go index f6b63890c..19b0466b0 100644 --- a/cmd/oras/root/manifest/push.go +++ b/cmd/oras/root/manifest/push.go @@ -192,7 +192,7 @@ func pushManifest(cmd *cobra.Command, opts pushOptions) error { } return opts.Output(os.Stdout, descJSON) } - if err := displayStatus.OnManifestPushed(opts.AnnotatedReference()); err != nil { + if err := displayMetadata.OnManifestPushed(); err != nil { return err } if len(opts.extraRefs) != 0 { From 04a587f6882611ae3b3d88dc9b6ff19db2d75ad8 Mon Sep 17 00:00:00 2001 From: Xiaoxuan Wang Date: Thu, 5 Dec 2024 16:00:23 +0800 Subject: [PATCH 09/15] change test Signed-off-by: Xiaoxuan Wang --- cmd/oras/internal/display/metadata/discard_test.go | 7 +++++++ cmd/oras/internal/display/status/discard.go | 11 +++-------- cmd/oras/internal/display/status/discard_test.go | 7 ------- cmd/oras/internal/display/status/interface.go | 4 ++-- cmd/oras/internal/display/status/text.go | 4 ++-- cmd/oras/root/manifest/push.go | 4 ++-- 6 files changed, 16 insertions(+), 21 deletions(-) diff --git a/cmd/oras/internal/display/metadata/discard_test.go b/cmd/oras/internal/display/metadata/discard_test.go index 9e9e67a8f..0e88f75e5 100644 --- a/cmd/oras/internal/display/metadata/discard_test.go +++ b/cmd/oras/internal/display/metadata/discard_test.go @@ -27,3 +27,10 @@ func TestDiscard_OnTagged(t *testing.T) { t.Errorf("testDiscard.OnTagged() error = %v, want nil", err) } } + +func TestDiscardHandler_OnManifestPushed(t *testing.T) { + testDiscard := NewDiscardHandler() + if err := testDiscard.OnManifestPushed(); err != nil { + t.Errorf("DiscardHandler.OnManifestPushed() error = %v, wantErr nil", err) + } +} diff --git a/cmd/oras/internal/display/status/discard.go b/cmd/oras/internal/display/status/discard.go index ab9bc1610..15c611e7e 100644 --- a/cmd/oras/internal/display/status/discard.go +++ b/cmd/oras/internal/display/status/discard.go @@ -105,18 +105,13 @@ func (DiscardHandler) OnPushSkipped() error { return nil } -// OnManifestUploading implements ManifestPushHandler. -func (DiscardHandler) OnManifestUploading() error { - return nil -} - -// OnManifestUploaded implements ManifestPushHandler. -func (DiscardHandler) OnManifestUploaded() error { +// OnManifestPushing implements ManifestPushHandler. +func (DiscardHandler) OnManifestPushing() error { return nil } // OnManifestPushed implements ManifestPushHandler. -func (DiscardHandler) OnManifestPushed(ref string) error { +func (DiscardHandler) OnManifestPushed() error { return nil } diff --git a/cmd/oras/internal/display/status/discard_test.go b/cmd/oras/internal/display/status/discard_test.go index 5df1a1c62..b7d5b83f8 100644 --- a/cmd/oras/internal/display/status/discard_test.go +++ b/cmd/oras/internal/display/status/discard_test.go @@ -21,13 +21,6 @@ import ( v1 "github.com/opencontainers/image-spec/specs-go/v1" ) -func TestDiscardHandler_OnManifestPushed(t *testing.T) { - testDiscard := NewDiscardHandler() - if err := testDiscard.OnManifestPushed("test"); err != nil { - t.Errorf("DiscardHandler.OnIndexMerged() error = %v, wantErr nil", err) - } -} - func TestDiscardHandler_OnPushSkipped(t *testing.T) { testDiscard := NewDiscardHandler() if err := testDiscard.OnPushSkipped(); err != nil { diff --git a/cmd/oras/internal/display/status/interface.go b/cmd/oras/internal/display/status/interface.go index abd0b1930..859b4966d 100644 --- a/cmd/oras/internal/display/status/interface.go +++ b/cmd/oras/internal/display/status/interface.go @@ -69,8 +69,8 @@ type CopyHandler interface { // ManifestPushHandler handles status output for manifest push command. type ManifestPushHandler interface { OnPushSkipped() error - OnManifestUploading() error - OnManifestUploaded() error + OnManifestPushing() error + OnManifestPushed() error } // ManifestIndexCreateHandler handles status output for manifest index create command. diff --git a/cmd/oras/internal/display/status/text.go b/cmd/oras/internal/display/status/text.go index 3b3c80d72..936b957d1 100644 --- a/cmd/oras/internal/display/status/text.go +++ b/cmd/oras/internal/display/status/text.go @@ -211,11 +211,11 @@ func (mph *TextManifestPushHandler) OnPushSkipped() error { return mph.printer.PrintStatus(mph.desc, PushPromptExists) } -func (mph *TextManifestPushHandler) OnManifestUploading() error { +func (mph *TextManifestPushHandler) OnManifestPushing() error { return mph.printer.PrintStatus(mph.desc, PushPromptUploading) } -func (mph *TextManifestPushHandler) OnManifestUploaded() error { +func (mph *TextManifestPushHandler) OnManifestPushed() error { return mph.printer.PrintStatus(mph.desc, PushPromptUploaded) } diff --git a/cmd/oras/root/manifest/push.go b/cmd/oras/root/manifest/push.go index 19b0466b0..edd095e36 100644 --- a/cmd/oras/root/manifest/push.go +++ b/cmd/oras/root/manifest/push.go @@ -165,13 +165,13 @@ func pushManifest(cmd *cobra.Command, opts pushOptions) error { return err } } else { - if err = displayStatus.OnManifestUploading(); err != nil { + if err = displayStatus.OnManifestPushing(); err != nil { return err } if _, err := oras.TagBytes(ctx, target, mediaType, contentBytes, ref); err != nil { return err } - if err = displayStatus.OnManifestUploaded(); err != nil { + if err = displayStatus.OnManifestPushed(); err != nil { return err } } From 75bb2a16ad0dd2c5d8523862b738661875643ede Mon Sep 17 00:00:00 2001 From: Xiaoxuan Wang Date: Fri, 6 Dec 2024 11:22:10 +0800 Subject: [PATCH 10/15] resolved comments Signed-off-by: Xiaoxuan Wang --- cmd/oras/internal/display/handler.go | 2 +- .../display/metadata/text/manifest_push.go | 4 ++-- cmd/oras/internal/display/status/utils.go | 1 - cmd/oras/root/manifest/push.go | 14 +++++++------- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/cmd/oras/internal/display/handler.go b/cmd/oras/internal/display/handler.go index 00fe84632..56bb9700c 100644 --- a/cmd/oras/internal/display/handler.go +++ b/cmd/oras/internal/display/handler.go @@ -170,7 +170,7 @@ func NewTagHandler(printer *output.Printer, target option.Target) metadata.TagHa } // NewManifestPushHandler returns a manifest push handler. -func NewManifestPushHandler(printer *output.Printer, outputDescriptor bool, pretty bool, desc ocispec.Descriptor, target option.Target) (status.ManifestPushHandler, metadata.ManifestPushHandler) { +func NewManifestPushHandler(printer *output.Printer, outputDescriptor bool, pretty bool, desc ocispec.Descriptor, target *option.Target) (status.ManifestPushHandler, metadata.ManifestPushHandler) { if outputDescriptor { return status.NewDiscardHandler(), metadata.NewDiscardHandler() } diff --git a/cmd/oras/internal/display/metadata/text/manifest_push.go b/cmd/oras/internal/display/metadata/text/manifest_push.go index 4983efccf..08984390a 100644 --- a/cmd/oras/internal/display/metadata/text/manifest_push.go +++ b/cmd/oras/internal/display/metadata/text/manifest_push.go @@ -25,11 +25,11 @@ import ( // ManifestPushHandler handles text metadata output for manifest push events. type ManifestPushHandler struct { printer *output.Printer - target option.Target + target *option.Target } // NewManifestPushHandler returns a new handler for manifest push events. -func NewManifestPushHandler(printer *output.Printer, target option.Target) metadata.ManifestPushHandler { +func NewManifestPushHandler(printer *output.Printer, target *option.Target) metadata.ManifestPushHandler { return &ManifestPushHandler{ printer: printer, target: target, diff --git a/cmd/oras/internal/display/status/utils.go b/cmd/oras/internal/display/status/utils.go index 26c65ab99..79662a72f 100644 --- a/cmd/oras/internal/display/status/utils.go +++ b/cmd/oras/internal/display/status/utils.go @@ -37,7 +37,6 @@ const ( PushPromptUploading = "Uploading" PushPromptSkipped = "Skipped " PushPromptExists = "Exists " - PushPromptPushed = "Pushed " ) // Prompts for cp events. diff --git a/cmd/oras/root/manifest/push.go b/cmd/oras/root/manifest/push.go index edd095e36..bb6555325 100644 --- a/cmd/oras/root/manifest/push.go +++ b/cmd/oras/root/manifest/push.go @@ -150,7 +150,7 @@ func pushManifest(cmd *cobra.Command, opts pushOptions) error { // prepare manifest descriptor desc := content.NewDescriptorFromBytes(mediaType, contentBytes) - displayStatus, displayMetadata := display.NewManifestPushHandler(opts.Printer, opts.OutputDescriptor, opts.Pretty.Pretty, desc, opts.Target) + statusHandler, metadataHandler := display.NewManifestPushHandler(opts.Printer, opts.OutputDescriptor, opts.Pretty.Pretty, desc, &opts.Target) ref := opts.Reference if ref == "" { @@ -161,17 +161,17 @@ func pushManifest(cmd *cobra.Command, opts pushOptions) error { return err } if match { - if err := displayStatus.OnPushSkipped(); err != nil { + if err := statusHandler.OnPushSkipped(); err != nil { return err } } else { - if err = displayStatus.OnManifestPushing(); err != nil { + if err = statusHandler.OnManifestPushing(); err != nil { return err } if _, err := oras.TagBytes(ctx, target, mediaType, contentBytes, ref); err != nil { return err } - if err = displayStatus.OnManifestPushed(); err != nil { + if err = statusHandler.OnManifestPushed(); err != nil { return err } } @@ -192,17 +192,17 @@ func pushManifest(cmd *cobra.Command, opts pushOptions) error { } return opts.Output(os.Stdout, descJSON) } - if err := displayMetadata.OnManifestPushed(); err != nil { + if err := metadataHandler.OnManifestPushed(); err != nil { return err } if len(opts.extraRefs) != 0 { - tagListener := listener.NewTaggedListener(target, displayMetadata.OnTagged) + tagListener := listener.NewTaggedListener(target, metadataHandler.OnTagged) if _, err = oras.TagBytesN(ctx, tagListener, mediaType, contentBytes, opts.extraRefs, tagBytesNOpts); err != nil { return err } } - return displayMetadata.OnCompleted(desc) + return metadataHandler.OnCompleted(desc) } // matchDigest checks whether the manifest's digest matches to it in the remote From f86953f7a3ec0c91e2226c74917f3141ba98d359 Mon Sep 17 00:00:00 2001 From: Xiaoxuan Wang Date: Mon, 16 Dec 2024 11:38:55 +0800 Subject: [PATCH 11/15] render interface Signed-off-by: Xiaoxuan Wang --- cmd/oras/internal/display/metadata/discard.go | 7 ++++++- cmd/oras/internal/display/metadata/discard_test.go | 2 +- cmd/oras/internal/display/metadata/interface.go | 5 +++-- .../internal/display/metadata/text/manifest_push.go | 10 ++++++---- cmd/oras/root/manifest/push.go | 4 ++-- 5 files changed, 18 insertions(+), 10 deletions(-) diff --git a/cmd/oras/internal/display/metadata/discard.go b/cmd/oras/internal/display/metadata/discard.go index f0eba312a..f2cf9d604 100644 --- a/cmd/oras/internal/display/metadata/discard.go +++ b/cmd/oras/internal/display/metadata/discard.go @@ -32,7 +32,12 @@ func (Discard) OnFetched(string, ocispec.Descriptor, []byte) error { } // OnManifestPushed implements ManifestPushHandler. -func (Discard) OnManifestPushed() error { +func (Discard) OnManifestPushed(ocispec.Descriptor) error { + return nil +} + +// Render implements ManifestPushHandler. +func (Discard) Render() error { return nil } diff --git a/cmd/oras/internal/display/metadata/discard_test.go b/cmd/oras/internal/display/metadata/discard_test.go index 0e88f75e5..c3d8f83f6 100644 --- a/cmd/oras/internal/display/metadata/discard_test.go +++ b/cmd/oras/internal/display/metadata/discard_test.go @@ -30,7 +30,7 @@ func TestDiscard_OnTagged(t *testing.T) { func TestDiscardHandler_OnManifestPushed(t *testing.T) { testDiscard := NewDiscardHandler() - if err := testDiscard.OnManifestPushed(); err != nil { + if err := testDiscard.OnManifestPushed(ocispec.Descriptor{}); err != nil { t.Errorf("DiscardHandler.OnManifestPushed() error = %v, wantErr nil", err) } } diff --git a/cmd/oras/internal/display/metadata/interface.go b/cmd/oras/internal/display/metadata/interface.go index 8ded81791..cc8d504c0 100644 --- a/cmd/oras/internal/display/metadata/interface.go +++ b/cmd/oras/internal/display/metadata/interface.go @@ -83,8 +83,9 @@ type TagHandler interface { // ManifestPushHandler handles metadata output for manifest push events. type ManifestPushHandler interface { TaggedHandler - OnManifestPushed() error - OnCompleted(desc ocispec.Descriptor) error + Renderer + + OnManifestPushed(desc ocispec.Descriptor) error } // ManifestIndexCreateHandler handles metadata output for index create events. diff --git a/cmd/oras/internal/display/metadata/text/manifest_push.go b/cmd/oras/internal/display/metadata/text/manifest_push.go index 08984390a..594de1245 100644 --- a/cmd/oras/internal/display/metadata/text/manifest_push.go +++ b/cmd/oras/internal/display/metadata/text/manifest_push.go @@ -26,6 +26,7 @@ import ( type ManifestPushHandler struct { printer *output.Printer target *option.Target + desc ocispec.Descriptor } // NewManifestPushHandler returns a new handler for manifest push events. @@ -42,11 +43,12 @@ func (h *ManifestPushHandler) OnTagged(_ ocispec.Descriptor, tag string) error { } // OnManifestPushed implements metadata.ManifestPushHandler. -func (h *ManifestPushHandler) OnManifestPushed() error { +func (h *ManifestPushHandler) OnManifestPushed(desc ocispec.Descriptor) error { + h.desc = desc return h.printer.Println("Pushed:", h.target.AnnotatedReference()) } -// OnCompleted implements metadata.ManifestPushHandler. -func (h *ManifestPushHandler) OnCompleted(desc ocispec.Descriptor) error { - return h.printer.Println("Digest:", desc.Digest) +// Render implements metadata.ManifestPushHandler. +func (h *ManifestPushHandler) Render() error { + return h.printer.Println("Digest:", h.desc.Digest) } diff --git a/cmd/oras/root/manifest/push.go b/cmd/oras/root/manifest/push.go index 2ec9415dd..5d5cbe20c 100644 --- a/cmd/oras/root/manifest/push.go +++ b/cmd/oras/root/manifest/push.go @@ -194,7 +194,7 @@ func pushManifest(cmd *cobra.Command, opts pushOptions) error { } return opts.Output(os.Stdout, descJSON) } - if err := metadataHandler.OnManifestPushed(); err != nil { + if err := metadataHandler.OnManifestPushed(desc); err != nil { return err } if len(opts.extraRefs) != 0 { @@ -204,7 +204,7 @@ func pushManifest(cmd *cobra.Command, opts pushOptions) error { } } - return metadataHandler.OnCompleted(desc) + return metadataHandler.Render() } // matchDigest checks whether the manifest's digest matches to it in the remote From ec2d0dbfa5dc3f2b964baaabbb864d6005042ddd Mon Sep 17 00:00:00 2001 From: Xiaoxuan Wang Date: Mon, 16 Dec 2024 11:49:27 +0800 Subject: [PATCH 12/15] fix Signed-off-by: Xiaoxuan Wang --- cmd/oras/internal/display/status/discard_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/oras/internal/display/status/discard_test.go b/cmd/oras/internal/display/status/discard_test.go index b7d5b83f8..50084963e 100644 --- a/cmd/oras/internal/display/status/discard_test.go +++ b/cmd/oras/internal/display/status/discard_test.go @@ -24,7 +24,7 @@ import ( func TestDiscardHandler_OnPushSkipped(t *testing.T) { testDiscard := NewDiscardHandler() if err := testDiscard.OnPushSkipped(); err != nil { - t.Errorf("DiscardHandler.OnIndexExists() error = %v, wantErr nil", err) + t.Errorf("DiscardHandler.OnPushSkipped() error = %v, wantErr nil", err) } } From d6bf0d8f7d34e24b1df84d6ba8385e3450dded43 Mon Sep 17 00:00:00 2001 From: Xiaoxuan Wang Date: Mon, 16 Dec 2024 14:57:58 +0800 Subject: [PATCH 13/15] resolved comment Signed-off-by: Xiaoxuan Wang --- cmd/oras/internal/display/status/discard.go | 4 ++-- cmd/oras/internal/display/status/discard_test.go | 2 +- cmd/oras/internal/display/status/interface.go | 2 +- cmd/oras/internal/display/status/text.go | 2 +- cmd/oras/internal/display/status/text_test.go | 2 +- cmd/oras/root/manifest/push.go | 4 +--- 6 files changed, 7 insertions(+), 9 deletions(-) diff --git a/cmd/oras/internal/display/status/discard.go b/cmd/oras/internal/display/status/discard.go index 15c611e7e..cf7b40358 100644 --- a/cmd/oras/internal/display/status/discard.go +++ b/cmd/oras/internal/display/status/discard.go @@ -100,8 +100,8 @@ func (DiscardHandler) OnFetched(string, ocispec.Descriptor) error { return nil } -// OnPushSkipped implements ManifestPushHandler. -func (DiscardHandler) OnPushSkipped() error { +// OnManifestPushSkipped implements ManifestPushHandler. +func (DiscardHandler) OnManifestPushSkipped() error { return nil } diff --git a/cmd/oras/internal/display/status/discard_test.go b/cmd/oras/internal/display/status/discard_test.go index 50084963e..757006941 100644 --- a/cmd/oras/internal/display/status/discard_test.go +++ b/cmd/oras/internal/display/status/discard_test.go @@ -23,7 +23,7 @@ import ( func TestDiscardHandler_OnPushSkipped(t *testing.T) { testDiscard := NewDiscardHandler() - if err := testDiscard.OnPushSkipped(); err != nil { + if err := testDiscard.OnManifestPushSkipped(); err != nil { t.Errorf("DiscardHandler.OnPushSkipped() error = %v, wantErr nil", err) } } diff --git a/cmd/oras/internal/display/status/interface.go b/cmd/oras/internal/display/status/interface.go index 859b4966d..b2e243d48 100644 --- a/cmd/oras/internal/display/status/interface.go +++ b/cmd/oras/internal/display/status/interface.go @@ -68,7 +68,7 @@ type CopyHandler interface { // ManifestPushHandler handles status output for manifest push command. type ManifestPushHandler interface { - OnPushSkipped() error + OnManifestPushSkipped() error OnManifestPushing() error OnManifestPushed() error } diff --git a/cmd/oras/internal/display/status/text.go b/cmd/oras/internal/display/status/text.go index 936b957d1..ee6852abb 100644 --- a/cmd/oras/internal/display/status/text.go +++ b/cmd/oras/internal/display/status/text.go @@ -207,7 +207,7 @@ func NewTextManifestPushHandler(printer *output.Printer, desc ocispec.Descriptor } } -func (mph *TextManifestPushHandler) OnPushSkipped() error { +func (mph *TextManifestPushHandler) OnManifestPushSkipped() error { return mph.printer.PrintStatus(mph.desc, PushPromptExists) } diff --git a/cmd/oras/internal/display/status/text_test.go b/cmd/oras/internal/display/status/text_test.go index 407db3f63..37770b533 100644 --- a/cmd/oras/internal/display/status/text_test.go +++ b/cmd/oras/internal/display/status/text_test.go @@ -196,7 +196,7 @@ func TestTextPushHandler_PreCopy(t *testing.T) { func TestTextManifestPushHandler_OnPushSkipped(t *testing.T) { mph := NewTextManifestPushHandler(printer, ocispec.Descriptor{}) - if mph.OnPushSkipped() != nil { + if mph.OnManifestPushSkipped() != nil { t.Error("OnManifestExists() should not return an error") } } diff --git a/cmd/oras/root/manifest/push.go b/cmd/oras/root/manifest/push.go index 5d5cbe20c..62f1ad951 100644 --- a/cmd/oras/root/manifest/push.go +++ b/cmd/oras/root/manifest/push.go @@ -101,7 +101,6 @@ Example - Push a manifest to an OCI image layout folder 'layout-dir' and tag wit return option.Parse(cmd, &opts) }, RunE: func(cmd *cobra.Command, args []string) error { - opts.Printer.Verbose = opts.verbose && !opts.OutputDescriptor return pushManifest(cmd, opts) }, } @@ -151,7 +150,6 @@ func pushManifest(cmd *cobra.Command, opts pushOptions) error { // prepare manifest descriptor desc := content.NewDescriptorFromBytes(mediaType, contentBytes) - statusHandler, metadataHandler := display.NewManifestPushHandler(opts.Printer, opts.OutputDescriptor, opts.Pretty.Pretty, desc, &opts.Target) ref := opts.Reference @@ -163,7 +161,7 @@ func pushManifest(cmd *cobra.Command, opts pushOptions) error { return err } if match { - if err := statusHandler.OnPushSkipped(); err != nil { + if err := statusHandler.OnManifestPushSkipped(); err != nil { return err } } else { From db839b0be9526aceaa1440290d0af04d0c35c829 Mon Sep 17 00:00:00 2001 From: Xiaoxuan Wang Date: Mon, 16 Dec 2024 15:06:58 +0800 Subject: [PATCH 14/15] add verbose back Signed-off-by: Xiaoxuan Wang --- cmd/oras/root/manifest/push.go | 1 + 1 file changed, 1 insertion(+) diff --git a/cmd/oras/root/manifest/push.go b/cmd/oras/root/manifest/push.go index 62f1ad951..84c357e1b 100644 --- a/cmd/oras/root/manifest/push.go +++ b/cmd/oras/root/manifest/push.go @@ -101,6 +101,7 @@ Example - Push a manifest to an OCI image layout folder 'layout-dir' and tag wit return option.Parse(cmd, &opts) }, RunE: func(cmd *cobra.Command, args []string) error { + opts.Printer.Verbose = opts.verbose && !opts.OutputDescriptor return pushManifest(cmd, opts) }, } From 5c3721a91b6329b996a3cb67c3db4e0cac3b7b4e Mon Sep 17 00:00:00 2001 From: Xiaoxuan Wang Date: Mon, 16 Dec 2024 15:38:43 +0800 Subject: [PATCH 15/15] fix failed test Signed-off-by: Xiaoxuan Wang --- cmd/oras/root/manifest/push.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/oras/root/manifest/push.go b/cmd/oras/root/manifest/push.go index 84c357e1b..57f07b18b 100644 --- a/cmd/oras/root/manifest/push.go +++ b/cmd/oras/root/manifest/push.go @@ -101,7 +101,7 @@ Example - Push a manifest to an OCI image layout folder 'layout-dir' and tag wit return option.Parse(cmd, &opts) }, RunE: func(cmd *cobra.Command, args []string) error { - opts.Printer.Verbose = opts.verbose && !opts.OutputDescriptor + opts.Printer.Verbose = opts.verbose return pushManifest(cmd, opts) }, }