diff --git a/cmd/oras/internal/display/track/target.go b/cmd/oras/internal/display/track/target.go index 5b640062f..28ac8c96f 100644 --- a/cmd/oras/internal/display/track/target.go +++ b/cmd/oras/internal/display/track/target.go @@ -30,7 +30,7 @@ import ( type GraphTarget interface { oras.GraphTarget io.Closer - Prompt(desc ocispec.Descriptor, prompt string, verbose bool) error + Prompt(desc ocispec.Descriptor, prompt string) error } type graphTarget struct { @@ -102,7 +102,7 @@ func (t *graphTarget) Close() error { } // Prompt prompts the user with the provided prompt and descriptor. -func (t *graphTarget) Prompt(desc ocispec.Descriptor, prompt string, verbose bool) error { +func (t *graphTarget) Prompt(desc ocispec.Descriptor, prompt string) error { status, err := t.manager.Add() if err != nil { return err diff --git a/cmd/oras/internal/display/track/target_test.go b/cmd/oras/internal/display/track/target_test.go index c66066cc9..a552ffdd3 100644 --- a/cmd/oras/internal/display/track/target_test.go +++ b/cmd/oras/internal/display/track/target_test.go @@ -73,3 +73,31 @@ func Test_referenceGraphTarget_PushReference(t *testing.T) { t.Fatal(err) } } + +func Test_referenceGraphTarget_Prompt(t *testing.T) { + // prepare + pty, device, err := testutils.NewPty() + if err != nil { + t.Fatal(err) + } + defer device.Close() + content := []byte("test") + desc := ocispec.Descriptor{ + MediaType: "application/octet-stream", + Digest: digest.FromBytes(content), + Size: int64(len(content)), + } + // test + prompt := "prompt" + target, err := NewTarget(memory.New(), "action", "done", device) + if err != nil { + t.Fatal(err) + } + m := target.(*graphTarget).manager + target.Prompt(desc, prompt) + m.Close() + // validate + if err = testutils.MatchPty(pty, device, prompt, desc.MediaType, "100.00%", desc.Digest.String()); err != nil { + t.Fatal(err) + } +} diff --git a/cmd/oras/root/cp.go b/cmd/oras/root/cp.go index 4437c3e35..8df14084f 100644 --- a/cmd/oras/root/cp.go +++ b/cmd/oras/root/cp.go @@ -180,12 +180,12 @@ func doCopy(ctx context.Context, src oras.ReadOnlyGraphTarget, dst oras.GraphTar dst = tracked extendedCopyOptions.OnCopySkipped = func(ctx context.Context, desc ocispec.Descriptor) error { committed.Store(desc.Digest.String(), desc.Annotations[ocispec.AnnotationTitle]) - return tracked.Prompt(desc, "Exists ", opts.Verbose) + return tracked.Prompt(desc, "Exists ") } extendedCopyOptions.PostCopy = func(ctx context.Context, desc ocispec.Descriptor) error { committed.Store(desc.Digest.String(), desc.Annotations[ocispec.AnnotationTitle]) return display.PrintSuccessorStatus(ctx, desc, tracked, committed, func(desc ocispec.Descriptor) error { - return tracked.Prompt(desc, "Skipped", opts.Verbose) + return tracked.Prompt(desc, "Skipped") }) } } diff --git a/cmd/oras/root/pull.go b/cmd/oras/root/pull.go index cfec01f18..064dcbf05 100644 --- a/cmd/oras/root/pull.go +++ b/cmd/oras/root/pull.go @@ -293,5 +293,5 @@ func printOnce(printed *sync.Map, s ocispec.Descriptor, msg string, verbose bool return display.PrintStatus(s, msg, verbose) } // TTY - return tracked.Prompt(s, msg, verbose) + return tracked.Prompt(s, msg) } diff --git a/cmd/oras/root/push.go b/cmd/oras/root/push.go index f45714570..6040e353e 100644 --- a/cmd/oras/root/push.go +++ b/cmd/oras/root/push.go @@ -263,12 +263,12 @@ func updateDisplayOption(opts *oras.CopyGraphOptions, fetcher content.Fetcher, v // TTY opts.OnCopySkipped = func(ctx context.Context, desc ocispec.Descriptor) error { committed.Store(desc.Digest.String(), desc.Annotations[ocispec.AnnotationTitle]) - return tracked.Prompt(desc, "Exists ", verbose) + return tracked.Prompt(desc, "Exists ") } opts.PostCopy = func(ctx context.Context, desc ocispec.Descriptor) error { committed.Store(desc.Digest.String(), desc.Annotations[ocispec.AnnotationTitle]) return display.PrintSuccessorStatus(ctx, desc, fetcher, committed, func(d ocispec.Descriptor) error { - return tracked.Prompt(d, "Skipped ", verbose) + return tracked.Prompt(d, "Skipped ") }) } }