restructure cli copy messages to print descriptor information

This commit is contained in:
Josh Wolf
2021-12-09 11:09:50 -07:00
parent cd93d7aaea
commit 7eabbdc0aa
3 changed files with 15 additions and 6 deletions
+12 -4
View File
@@ -2,9 +2,10 @@ package store
import (
"context"
"fmt"
"strings"
"github.com/pkg/errors"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/spf13/cobra"
"oras.land/oras-go/pkg/content"
@@ -33,6 +34,7 @@ func (o *CopyOpts) AddFlags(cmd *cobra.Command) {
func CopyCmd(ctx context.Context, o *CopyOpts, s *store.Store, targetRef string) error {
l := log.FromContext(ctx)
var descs []ocispec.Descriptor
components := strings.SplitN(targetRef, "://", 2)
switch components[0] {
case "dir":
@@ -40,9 +42,11 @@ func CopyCmd(ctx context.Context, o *CopyOpts, s *store.Store, targetRef string)
fs := content.NewFile(components[1])
defer fs.Close()
if err := s.CopyAll(ctx, fs, nil); err != nil {
ds, err := s.CopyAll(ctx, fs, nil)
if err != nil {
return err
}
descs = ds
case "registry":
l.Debugf("identified registry target reference")
@@ -64,12 +68,16 @@ func CopyCmd(ctx context.Context, o *CopyOpts, s *store.Store, targetRef string)
return ref.Name(), nil
}
if err := s.CopyAll(ctx, r, mapperFn); err != nil {
ds, err := s.CopyAll(ctx, r, mapperFn)
if err != nil {
return err
}
descs = ds
default:
return errors.Errorf("determining target protocol from: [%s]", targetRef)
return fmt.Errorf("detecting protocol from [%s]", targetRef)
}
l.Infof("Copied [%d] artifacts to [%s]", len(descs), components[1])
return nil
}
+2 -2
View File
@@ -29,12 +29,12 @@ func (o *InfoOpts) AddFlags(cmd *cobra.Command) {
func InfoCmd(ctx context.Context, o *InfoOpts, s *store.Store) error {
var items []item
if err := s.Walk(func(desc ocispec.Descriptor) error {
if err := s.Store.Walk(func(ref string, desc ocispec.Descriptor) error {
if _, ok := desc.Annotations[ocispec.AnnotationRefName]; !ok {
return nil
}
rc, err := s.Open(ctx, desc)
rc, err := s.Store.Fetch(ctx, desc)
if err != nil {
return err
}
+1
View File
@@ -66,6 +66,7 @@ func NewTempRegistry(ctx context.Context, root string) *tmpRegistryServer {
}
}
// Registry returns the URL of the server without the protocol, suitable for content references
func (t *tmpRegistryServer) Registry() string {
return strings.Replace(t.Server.URL, "http://", "", 1)
}