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: Clean up pull handlers #1407

Merged
merged 2 commits into from
Jun 17, 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
10 changes: 2 additions & 8 deletions cmd/oras/internal/display/status/text.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,6 @@ func (ph *TextPushHandler) TrackTarget(gt oras.GraphTarget) (oras.GraphTarget, S

// UpdateCopyOptions adds status update to the copy options.
func (ph *TextPushHandler) UpdateCopyOptions(opts *oras.CopyGraphOptions, fetcher content.Fetcher) {
const (
promptSkipped = "Skipped "
promptUploaded = "Uploaded "
promptExists = "Exists "
promptUploading = "Uploading"
)
committed := &sync.Map{}
opts.OnCopySkipped = func(ctx context.Context, desc ocispec.Descriptor) error {
committed.Store(desc.Digest.String(), desc.Annotations[ocispec.AnnotationTitle])
Expand Down Expand Up @@ -94,7 +88,7 @@ type TextPullHandler struct {
printer *output.Printer
}

// TrackTarget implements PullHander.
// TrackTarget implements PullHandler.
func (ph *TextPullHandler) TrackTarget(gt oras.GraphTarget) (oras.GraphTarget, StopTrackTargetFunc, error) {
return gt, discardStopTrack, nil
}
Expand All @@ -119,7 +113,7 @@ func (ph *TextPullHandler) OnNodeProcessing(desc ocispec.Descriptor) error {
return ph.printer.PrintStatus(desc, PullPromptProcessing, ph.verbose)
}

// OnNodeProcessing implements PullHandler.
// OnNodeSkipped implements PullHandler.
func (ph *TextPullHandler) OnNodeSkipped(desc ocispec.Descriptor) error {
return ph.printer.PrintStatus(desc, PullPromptSkipped, ph.verbose)
}
Expand Down
18 changes: 5 additions & 13 deletions cmd/oras/internal/display/status/tty.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func NewTTYPushHandler(tty *os.File) PushHandler {
}

// OnFileLoading is called before loading a file.
func (ph *TTYPushHandler) OnFileLoading(name string) error {
func (ph *TTYPushHandler) OnFileLoading(_ string) error {
return nil
}

Expand All @@ -52,10 +52,6 @@ func (ph *TTYPushHandler) OnEmptyArtifact() error {

// TrackTarget returns a tracked target.
func (ph *TTYPushHandler) TrackTarget(gt oras.GraphTarget) (oras.GraphTarget, StopTrackTargetFunc, error) {
const (
promptUploaded = "Uploaded "
promptUploading = "Uploading"
)
tracked, err := track.NewTarget(gt, promptUploading, promptUploaded, ph.tty)
if err != nil {
return nil, nil, err
Expand All @@ -66,10 +62,6 @@ func (ph *TTYPushHandler) TrackTarget(gt oras.GraphTarget) (oras.GraphTarget, St

// UpdateCopyOptions adds TTY status output to the copy options.
func (ph *TTYPushHandler) UpdateCopyOptions(opts *oras.CopyGraphOptions, fetcher content.Fetcher) {
const (
promptSkipped = "Skipped "
promptExists = "Exists "
)
committed := &sync.Map{}
opts.OnCopySkipped = func(ctx context.Context, desc ocispec.Descriptor) error {
committed.Store(desc.Digest.String(), desc.Annotations[ocispec.AnnotationTitle])
Expand Down Expand Up @@ -102,17 +94,17 @@ func NewTTYPullHandler(tty *os.File) PullHandler {
}

// OnNodeDownloading implements PullHandler.
func (ph *TTYPullHandler) OnNodeDownloading(desc ocispec.Descriptor) error {
func (ph *TTYPullHandler) OnNodeDownloading(_ ocispec.Descriptor) error {
return nil
}

// OnNodeDownloaded implements PullHandler.
func (ph *TTYPullHandler) OnNodeDownloaded(desc ocispec.Descriptor) error {
func (ph *TTYPullHandler) OnNodeDownloaded(_ ocispec.Descriptor) error {
return nil
}

// OnNodeProcessing implements PullHandler.
func (ph *TTYPullHandler) OnNodeProcessing(desc ocispec.Descriptor) error {
func (ph *TTYPullHandler) OnNodeProcessing(_ ocispec.Descriptor) error {
return nil
}

Expand All @@ -121,7 +113,7 @@ func (ph *TTYPullHandler) OnNodeRestored(desc ocispec.Descriptor) error {
return ph.tracked.Prompt(desc, PullPromptRestored)
}

// OnNodeProcessing implements PullHandler.
// OnNodeSkipped implements PullHandler.
func (ph *TTYPullHandler) OnNodeSkipped(desc ocispec.Descriptor) error {
return ph.tracked.Prompt(desc, PullPromptSkipped)
}
Expand Down
4 changes: 4 additions & 0 deletions cmd/oras/internal/display/status/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,8 @@ const (
PullPromptSkipped = "Skipped "
PullPromptRestored = "Restored "
PullPromptDownloaded = "Downloaded "
promptUploaded = "Uploaded "
promptUploading = "Uploading"
promptSkipped = "Skipped "
promptExists = "Exists "
)
Loading