Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Get rid of deprecated PrintStatus method #1378

Merged
merged 3 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions cmd/oras/internal/display/status/deprecated.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,6 @@ func Print(a ...any) error {
return printer.Println(a...)
}

// StatusPrinter returns a tracking function for transfer status.
func StatusPrinter(status string, verbose bool) PrintFunc {
return printer.StatusPrinter(status, verbose)
}

// PrintStatus prints transfer status.
func PrintStatus(desc ocispec.Descriptor, status string, verbose bool) error {
return printer.PrintStatus(desc, status, verbose)
Expand Down
15 changes: 8 additions & 7 deletions cmd/oras/root/cp.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ Example - Copy an artifact with multiple tags with concurrency tuned:

func runCopy(cmd *cobra.Command, opts *copyOptions) error {
ctx, logger := command.GetLogger(cmd, &opts.Common)
printer := status.NewPrinter(cmd.OutOrStdout())

// Prepare source
src, err := opts.From.NewReadonlyTarget(ctx, opts.Common, logger)
Expand All @@ -126,7 +127,7 @@ func runCopy(cmd *cobra.Command, opts *copyOptions) error {
}
ctx = registryutil.WithScopeHint(ctx, dst, auth.ActionPull, auth.ActionPush)

desc, err := doCopy(ctx, src, dst, opts)
desc, err := doCopy(ctx, printer, src, dst, opts)
if err != nil {
return err
}
Expand All @@ -151,7 +152,7 @@ func runCopy(cmd *cobra.Command, opts *copyOptions) error {
return nil
}

func doCopy(ctx context.Context, src oras.ReadOnlyGraphTarget, dst oras.GraphTarget, opts *copyOptions) (ocispec.Descriptor, error) {
func doCopy(ctx context.Context, printer *status.Printer, src oras.ReadOnlyGraphTarget, dst oras.GraphTarget, opts *copyOptions) (ocispec.Descriptor, error) {
// Prepare copy options
committed := &sync.Map{}
extendedCopyOptions := oras.DefaultExtendedCopyOptions
Expand All @@ -178,21 +179,21 @@ func doCopy(ctx context.Context, src oras.ReadOnlyGraphTarget, dst oras.GraphTar
// none TTY output
extendedCopyOptions.OnCopySkipped = func(ctx context.Context, desc ocispec.Descriptor) error {
committed.Store(desc.Digest.String(), desc.Annotations[ocispec.AnnotationTitle])
return status.PrintStatus(desc, promptExists, opts.Verbose)
return printer.PrintStatus(desc, promptExists, opts.Verbose)
}
extendedCopyOptions.PreCopy = func(ctx context.Context, desc ocispec.Descriptor) error {
return status.PrintStatus(desc, promptCopying, opts.Verbose)
return printer.PrintStatus(desc, promptCopying, opts.Verbose)
}
extendedCopyOptions.PostCopy = func(ctx context.Context, desc ocispec.Descriptor) error {
committed.Store(desc.Digest.String(), desc.Annotations[ocispec.AnnotationTitle])
if err := status.PrintSuccessorStatus(ctx, desc, dst, committed, status.StatusPrinter(promptSkipped, opts.Verbose)); err != nil {
if err := status.PrintSuccessorStatus(ctx, desc, dst, committed, printer.StatusPrinter(promptSkipped, opts.Verbose)); err != nil {
return err
}
return status.PrintStatus(desc, promptCopied, opts.Verbose)
return printer.PrintStatus(desc, promptCopied, opts.Verbose)
}
extendedCopyOptions.OnMounted = func(ctx context.Context, desc ocispec.Descriptor) error {
committed.Store(desc.Digest.String(), desc.Annotations[ocispec.AnnotationTitle])
return status.PrintStatus(desc, promptMounted, opts.Verbose)
return printer.PrintStatus(desc, promptMounted, opts.Verbose)
}
} else {
// TTY output
Expand Down
14 changes: 11 additions & 3 deletions cmd/oras/root/cp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ import (
"net/http"
"net/http/httptest"
"net/url"
"oras.land/oras/cmd/oras/internal/display/status"
"os"
"strings"
"testing"

"github.com/opencontainers/go-digest"
Expand Down Expand Up @@ -129,8 +131,10 @@ func Test_doCopy(t *testing.T) {
opts.Verbose = true
opts.From.Reference = memDesc.Digest.String()
dst := memory.New()
builder := &strings.Builder{}
printer := status.NewPrinter(builder)
// test
_, err = doCopy(context.Background(), memStore, dst, &opts)
_, err = doCopy(context.Background(), printer, memStore, dst, &opts)
if err != nil {
t.Fatal(err)
}
Expand All @@ -151,8 +155,10 @@ func Test_doCopy_skipped(t *testing.T) {
opts.TTY = slave
opts.Verbose = true
opts.From.Reference = memDesc.Digest.String()
builder := &strings.Builder{}
printer := status.NewPrinter(builder)
// test
_, err = doCopy(context.Background(), memStore, memStore, &opts)
_, err = doCopy(context.Background(), printer, memStore, memStore, &opts)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -184,8 +190,10 @@ func Test_doCopy_mounted(t *testing.T) {
t.Fatal(err)
}
to.PlainHTTP = true
builder := &strings.Builder{}
printer := status.NewPrinter(builder)
// test
_, err = doCopy(context.Background(), from, to, &opts)
_, err = doCopy(context.Background(), printer, from, to, &opts)
if err != nil {
t.Fatal(err)
}
Expand Down
Loading