-
Notifications
You must be signed in to change notification settings - Fork 181
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: Create tracked reader interface #1511
Conversation
Signed-off-by: Terry Howe <[email protected]>
7df760f
to
0a4e476
Compare
@@ -23,6 +23,14 @@ import ( | |||
"oras.land/oras/cmd/oras/internal/display/status/progress" | |||
) | |||
|
|||
type Reader interface { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need comment doc for this interface.
@@ -74,7 +76,7 @@ func (t *graphTarget) Mount(ctx context.Context, desc ocispec.Descriptor, fromRe | |||
|
|||
// Push pushes the content to the base oras.GraphTarget with tracking. | |||
func (t *graphTarget) Push(ctx context.Context, expected ocispec.Descriptor, content io.Reader) error { | |||
r, err := managedReader(content, expected, t.manager, t.actionPrompt, t.donePrompt) | |||
r, err := NewReader(content, expected, t.actionPrompt, t.donePrompt, t.tty) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A manager controls output to tty and cannot be be shared between track.Reader
s. I think that's why the unit tests are failing.
func NewReader(r io.Reader, descriptor ocispec.Descriptor, actionPrompt string, donePrompt string, tty *os.File) (Reader, error) { | ||
manager, err := progress.NewManager(tty) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return managedReader(r, descriptor, manager, actionPrompt, donePrompt) | ||
} | ||
|
||
func managedReader(r io.Reader, descriptor ocispec.Descriptor, manager progress.Manager, actionPrompt string, donePrompt string) (*reader, error) { | ||
messenger, err := manager.Add() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &reader{ | ||
tr := reader{ | ||
base: r, | ||
descriptor: descriptor, | ||
actionPrompt: actionPrompt, | ||
donePrompt: donePrompt, | ||
manager: manager, | ||
messenger: messenger, | ||
}, nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not right to merge managedReader
into NewReader
. I would suggest to move it to target.go
.
@@ -35,6 +35,7 @@ type GraphTarget interface { | |||
|
|||
type graphTarget struct { | |||
oras.GraphTarget | |||
tty *os.File |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Manager should be the only way to access tty, trackable readers or targets should not access tty directly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The weirdness here is because this PR is part of #1474
Now that the console interface has merged, maybe the older PR is small enough
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Terry for contributing. The overall direction of this PR is good but still need some refinement on the detail.
What this PR does / why we need it:
Create an interface for the tracked reader.
This breaks out a small change from #1474