From 8c94001a83387af50eb3c51560c33dccd14ca5af Mon Sep 17 00:00:00 2001 From: Xiaoxuan Wang Date: Wed, 4 Sep 2024 10:37:36 +0800 Subject: [PATCH] resolved comments Signed-off-by: Xiaoxuan Wang --- cmd/oras/internal/display/handler.go | 6 +++--- cmd/oras/internal/display/metadata/interface.go | 4 ++-- .../metadata/text/manifest_index_create.go | 12 ++++++------ cmd/oras/root/manifest/index/create.go | 15 +++++++++------ internal/descriptor/descriptor.go | 5 +++-- 5 files changed, 23 insertions(+), 19 deletions(-) diff --git a/cmd/oras/internal/display/handler.go b/cmd/oras/internal/display/handler.go index 2bfb740b5..ccad542aa 100644 --- a/cmd/oras/internal/display/handler.go +++ b/cmd/oras/internal/display/handler.go @@ -174,9 +174,9 @@ func NewManifestPushHandler(printer *output.Printer) metadata.ManifestPushHandle return text.NewManifestPushHandler(printer) } -// NewIndexCreateHandler returns an index create handler. -func NewIndexCreateHandler(printer *output.Printer) metadata.IndexCreateHandler { - return text.NewIndexCreateHandler(printer) +// NewManifestIndexCreateHandler returns an index create handler. +func NewManifestIndexCreateHandler(printer *output.Printer) metadata.ManifestIndexCreateHandler { + return text.NewManifestIndexCreateHandler(printer) } // NewCopyHandler returns copy handlers. diff --git a/cmd/oras/internal/display/metadata/interface.go b/cmd/oras/internal/display/metadata/interface.go index a90466717..12c10b87b 100644 --- a/cmd/oras/internal/display/metadata/interface.go +++ b/cmd/oras/internal/display/metadata/interface.go @@ -78,8 +78,8 @@ type ManifestPushHandler interface { TaggedHandler } -// IndexCreateHandler handles metadata output for index create events. -type IndexCreateHandler interface { +// ManifestIndexCreateHandler handles metadata output for index create events. +type ManifestIndexCreateHandler interface { TaggedHandler } diff --git a/cmd/oras/internal/display/metadata/text/manifest_index_create.go b/cmd/oras/internal/display/metadata/text/manifest_index_create.go index 92226b344..960f676c2 100644 --- a/cmd/oras/internal/display/metadata/text/manifest_index_create.go +++ b/cmd/oras/internal/display/metadata/text/manifest_index_create.go @@ -21,19 +21,19 @@ import ( "oras.land/oras/cmd/oras/internal/output" ) -// IndexCreateHandler handles text metadata output for index create events. -type IndexCreateHandler struct { +// ManifestIndexCreateHandler handles text metadata output for index create events. +type ManifestIndexCreateHandler struct { printer *output.Printer } -// NewIndexCreateHandler returns a new handler for index create events. -func NewIndexCreateHandler(printer *output.Printer) metadata.IndexCreateHandler { - return &IndexCreateHandler{ +// NewManifestIndexCreateHandler returns a new handler for index create events. +func NewManifestIndexCreateHandler(printer *output.Printer) metadata.ManifestIndexCreateHandler { + return &ManifestIndexCreateHandler{ printer: printer, } } // OnTagged implements metadata.TaggedHandler. -func (h *IndexCreateHandler) OnTagged(_ ocispec.Descriptor, tag string) error { +func (h *ManifestIndexCreateHandler) OnTagged(_ ocispec.Descriptor, tag string) error { return h.printer.Println("Tagged", tag) } diff --git a/cmd/oras/root/manifest/index/create.go b/cmd/oras/root/manifest/index/create.go index 9e701e30a..9b2dfca26 100644 --- a/cmd/oras/root/manifest/index/create.go +++ b/cmd/oras/root/manifest/index/create.go @@ -57,14 +57,17 @@ func createCmd() *cobra.Command { Example - create an index from source manifests tagged 'linux-amd64' and 'linux-arm64', and push without tagging: oras manifest index create localhost:5000/hello linux-amd64 linux-arm64 -Example - create an index from source manifests tagged 'linux-amd64' and 'linux-arm64', and push with the tag 'latest': - oras manifest index create localhost:5000/hello:latest linux-amd64 linux-arm64 +Example - create an index from source manifests tagged 'linux-amd64' and 'linux-arm64', and push with the tag 'v1': + oras manifest index create localhost:5000/hello:v1 linux-amd64 linux-arm64 -Example - create an index from source manifests using both tags and digests, and push with tag 'latest': - oras manifest index create localhost:5000/hello:latest linux-amd64 sha256:xxx +Example - create an index from source manifests using both tags and digests, and push with tag 'v1': + oras manifest index create localhost:5000/hello:v1 linux-amd64 sha256:99e4703fbf30916f549cd6bfa9cdbab614b5392fbe64fdee971359a77073cdf9 Example - create an index and push it with multiple tags: - oras manifest index create localhost:5000/hello:tag1,tag2,tag3 linux-amd64 linux-arm64 sha256:xxx + oras manifest index create localhost:5000/hello:tag1,tag2,tag3 linux-amd64 linux-arm64 sha256:99e4703fbf30916f549cd6bfa9cdbab614b5392fbe64fdee971359a77073cdf9 + +Example - create an index and push to an OCI image layout folder 'layout-dir' and tag with 'v1': + oras manifest index create layout-dir:v1 linux-amd64 sha256:99e4703fbf30916f549cd6bfa9cdbab614b5392fbe64fdee971359a77073cdf9 `, Args: oerrors.CheckArgs(argument.AtLeast(1), "the destination index to create."), PreRunE: func(cmd *cobra.Command, args []string) error { @@ -175,7 +178,7 @@ func pushIndex(ctx context.Context, target oras.Target, desc ocispec.Descriptor, } printer.Println(status.IndexPromptPushed, path) if len(extraRefs) != 0 { - handler := display.NewIndexCreateHandler(printer) + handler := display.NewManifestIndexCreateHandler(printer) tagListener := listener.NewTaggedListener(target, handler.OnTagged) if _, err = oras.TagBytesN(ctx, tagListener, desc.MediaType, content, extraRefs, oras.DefaultTagBytesNOptions); err != nil { return err diff --git a/internal/descriptor/descriptor.go b/internal/descriptor/descriptor.go index f5098f1f1..b86849c33 100644 --- a/internal/descriptor/descriptor.go +++ b/internal/descriptor/descriptor.go @@ -21,7 +21,8 @@ import ( "oras.land/oras/internal/docker" ) -// IsManifest checks if a descriptor describes a manifest. +// IsManifest checks if a descriptor describes a manifest. Copied from oras-go with +// slight modification. func IsManifest(desc ocispec.Descriptor) bool { switch desc.MediaType { case docker.MediaTypeManifest, @@ -51,7 +52,7 @@ func ShortDigest(desc ocispec.Descriptor) (digestString string) { } // Plain returns a plain descriptor that contains only MediaType, Digest and -// Size. +// Size. Copied from oras-go. func Plain(desc ocispec.Descriptor) ocispec.Descriptor { return ocispec.Descriptor{ MediaType: desc.MediaType,