From d973d765f6cc92471c4b76ed6c3421cbbfa3c787 Mon Sep 17 00:00:00 2001 From: Terry Howe Date: Fri, 14 Jun 2024 13:48:16 -0600 Subject: [PATCH] refactor: Clean up pull handlers Signed-off-by: Terry Howe --- cmd/oras/internal/display/status/text.go | 10 ++-------- cmd/oras/internal/display/status/tty.go | 18 +++++------------- cmd/oras/internal/display/status/utils.go | 4 ++++ 3 files changed, 11 insertions(+), 21 deletions(-) diff --git a/cmd/oras/internal/display/status/text.go b/cmd/oras/internal/display/status/text.go index e68c89924..39cd1c82d 100644 --- a/cmd/oras/internal/display/status/text.go +++ b/cmd/oras/internal/display/status/text.go @@ -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]) @@ -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 } @@ -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) } diff --git a/cmd/oras/internal/display/status/tty.go b/cmd/oras/internal/display/status/tty.go index 75cf6b46a..fe19d05d6 100644 --- a/cmd/oras/internal/display/status/tty.go +++ b/cmd/oras/internal/display/status/tty.go @@ -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 } @@ -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 @@ -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]) @@ -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 } @@ -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) } diff --git a/cmd/oras/internal/display/status/utils.go b/cmd/oras/internal/display/status/utils.go index 5fc3af81b..0dd93fb96 100644 --- a/cmd/oras/internal/display/status/utils.go +++ b/cmd/oras/internal/display/status/utils.go @@ -31,4 +31,8 @@ const ( PullPromptSkipped = "Skipped " PullPromptRestored = "Restored " PullPromptDownloaded = "Downloaded " + promptUploaded = "Uploaded " + promptUploading = "Uploading" + promptSkipped = "Skipped " + promptExists = "Exists " )