mirror of
https://github.com/hauler-dev/hauler.git
synced 2026-08-27 14:07:17 +00:00
restructure cli copy messages to print descriptor information
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user