diff --git a/cmd/oras/internal/display/status/progress/manager.go b/cmd/oras/internal/display/status/progress/manager.go index b17d61e00..385c02a6d 100644 --- a/cmd/oras/internal/display/status/progress/manager.go +++ b/cmd/oras/internal/display/status/progress/manager.go @@ -21,6 +21,7 @@ import ( "sync" "time" + ocispec "github.com/opencontainers/image-spec/specs-go/v1" "oras.land/oras/cmd/oras/internal/display/status/console" ) @@ -39,6 +40,7 @@ type Status chan *status // Manager is progress view master type Manager interface { Add() (Status, error) + Send(desc ocispec.Descriptor, prompt string) error Close() error } @@ -120,6 +122,17 @@ func (m *manager) Add() (Status, error) { return m.statusChan(s), nil } +func (m *manager) Send(desc ocispec.Descriptor, prompt string) error { + status, err := m.Add() + if err != nil { + return err + } + defer close(status) + status <- NewStatusMessage(prompt, desc, desc.Size) + status <- EndTiming() + return nil +} + func (m *manager) statusChan(s *status) Status { ch := make(chan *status, BufferSize) m.updating.Add(1) diff --git a/cmd/oras/internal/display/status/track/target.go b/cmd/oras/internal/display/status/track/target.go index 9bd54d240..ad1c309c7 100644 --- a/cmd/oras/internal/display/status/track/target.go +++ b/cmd/oras/internal/display/status/track/target.go @@ -110,12 +110,5 @@ func (t *graphTarget) Close() error { // Prompt prompts the user with the provided prompt and descriptor. func (t *graphTarget) Prompt(desc ocispec.Descriptor, prompt string) error { - status, err := t.manager.Add() - if err != nil { - return err - } - defer close(status) - status <- progress.NewStatusMessage(prompt, desc, desc.Size) - status <- progress.EndTiming() - return nil + return t.manager.Send(desc, prompt) }