Skip to content

Commit

Permalink
refactor: Move handlers to handler package
Browse files Browse the repository at this point in the history
Signed-off-by: Terry Howe <[email protected]>
  • Loading branch information
TerryHowe committed May 28, 2024
1 parent 9ff316c commit 356b00b
Show file tree
Hide file tree
Showing 76 changed files with 115 additions and 110 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package status
package display

import (
"context"
Expand Down Expand Up @@ -47,7 +47,7 @@ func (p *Printer) Println(a ...any) error {
defer p.lock.Unlock()
_, err := fmt.Fprintln(p.out, a...)
if err != nil {
err = fmt.Errorf("display output error: %w", err)
err = fmt.Errorf("handler output error: %w", err)
_, _ = fmt.Fprint(os.Stderr, err)
}
// Errors are handled above, so return nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package status
package display

import (
"fmt"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"sync"
"time"

"oras.land/oras/cmd/oras/internal/display/status/console"
"oras.land/oras/cmd/oras/internal/display/console"
)

const (
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (

"github.com/morikuni/aec"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"oras.land/oras/cmd/oras/internal/display/status/progress/humanize"
"oras.land/oras/cmd/oras/internal/display/progress/humanize"
)

const (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ import (
"time"

ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"oras.land/oras/cmd/oras/internal/display/status/console"
"oras.land/oras/cmd/oras/internal/display/status/console/testutils"
"oras.land/oras/cmd/oras/internal/display/status/progress/humanize"
"oras.land/oras/cmd/oras/internal/display/console"
"oras.land/oras/cmd/oras/internal/display/console/testutils"
"oras.land/oras/cmd/oras/internal/display/progress/humanize"
)

func Test_status_String(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"os"

ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"oras.land/oras/cmd/oras/internal/display/utils"
"oras.land/oras/cmd/oras/internal/handler/utils"
)

// manifestFetch handles raw content output.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,24 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package display
package handler

import (
"io"
"os"

ocispec "github.com/opencontainers/image-spec/specs-go/v1"

"oras.land/oras/cmd/oras/internal/display/content"
"oras.land/oras/cmd/oras/internal/display/metadata"
"oras.land/oras/cmd/oras/internal/display/metadata/descriptor"
"oras.land/oras/cmd/oras/internal/display/metadata/json"
"oras.land/oras/cmd/oras/internal/display/metadata/table"
"oras.land/oras/cmd/oras/internal/display/metadata/template"
"oras.land/oras/cmd/oras/internal/display/metadata/text"
"oras.land/oras/cmd/oras/internal/display/metadata/tree"
"oras.land/oras/cmd/oras/internal/display/status"
"oras.land/oras/cmd/oras/internal/errors"
"oras.land/oras/cmd/oras/internal/handler/content"
"oras.land/oras/cmd/oras/internal/handler/metadata"
"oras.land/oras/cmd/oras/internal/handler/metadata/descriptor"
"oras.land/oras/cmd/oras/internal/handler/metadata/json"
"oras.land/oras/cmd/oras/internal/handler/metadata/table"
"oras.land/oras/cmd/oras/internal/handler/metadata/template"
"oras.land/oras/cmd/oras/internal/handler/metadata/text"
"oras.land/oras/cmd/oras/internal/handler/metadata/tree"
"oras.land/oras/cmd/oras/internal/handler/status"
"oras.land/oras/cmd/oras/internal/option"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import (
"io"

ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"oras.land/oras/cmd/oras/internal/display/metadata"
"oras.land/oras/cmd/oras/internal/display/utils"
"oras.land/oras/cmd/oras/internal/handler/metadata"
"oras.land/oras/cmd/oras/internal/handler/utils"
)

// manifestFetchHandler handles metadata descriptor output.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import (
"io"

ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"oras.land/oras/cmd/oras/internal/display/metadata"
"oras.land/oras/cmd/oras/internal/display/metadata/model"
"oras.land/oras/cmd/oras/internal/display/utils"
"oras.land/oras/cmd/oras/internal/handler/metadata"
"oras.land/oras/cmd/oras/internal/handler/metadata/model"
"oras.land/oras/cmd/oras/internal/handler/utils"
"oras.land/oras/cmd/oras/internal/option"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ import (

ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"oras.land/oras-go/v2/content"
"oras.land/oras/cmd/oras/internal/display/metadata"
"oras.land/oras/cmd/oras/internal/display/metadata/model"
"oras.land/oras/cmd/oras/internal/display/utils"
"oras.land/oras/cmd/oras/internal/handler/metadata"
"oras.land/oras/cmd/oras/internal/handler/metadata/model"
"oras.land/oras/cmd/oras/internal/handler/utils"
)

// discoverHandler handles json metadata output for discover events.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import (
"io"

ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"oras.land/oras/cmd/oras/internal/display/metadata"
"oras.land/oras/cmd/oras/internal/display/metadata/model"
"oras.land/oras/cmd/oras/internal/display/utils"
"oras.land/oras/cmd/oras/internal/handler/metadata"
"oras.land/oras/cmd/oras/internal/handler/metadata/model"
"oras.land/oras/cmd/oras/internal/handler/utils"
)

// manifestFetchHandler handles JSON metadata output for manifest fetch events.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import (
"io"

ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"oras.land/oras/cmd/oras/internal/display/metadata"
"oras.land/oras/cmd/oras/internal/display/metadata/model"
"oras.land/oras/cmd/oras/internal/display/utils"
"oras.land/oras/cmd/oras/internal/handler/metadata"
"oras.land/oras/cmd/oras/internal/handler/metadata/model"
"oras.land/oras/cmd/oras/internal/handler/utils"
"oras.land/oras/cmd/oras/internal/option"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import (
"io"

ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"oras.land/oras/cmd/oras/internal/display/metadata"
"oras.land/oras/cmd/oras/internal/display/metadata/model"
"oras.land/oras/cmd/oras/internal/display/utils"
"oras.land/oras/cmd/oras/internal/handler/metadata"
"oras.land/oras/cmd/oras/internal/handler/metadata/model"
"oras.land/oras/cmd/oras/internal/handler/utils"
"oras.land/oras/cmd/oras/internal/option"
"oras.land/oras/internal/contentutil"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import (

ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"oras.land/oras-go/v2/content"
"oras.land/oras/cmd/oras/internal/display/metadata"
"oras.land/oras/cmd/oras/internal/display/utils"
"oras.land/oras/cmd/oras/internal/handler/metadata"
"oras.land/oras/cmd/oras/internal/handler/utils"
)

// discoverHandler handles json metadata output for discover events.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import (
"io"

ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"oras.land/oras/cmd/oras/internal/display/metadata"
"oras.land/oras/cmd/oras/internal/display/metadata/model"
"oras.land/oras/cmd/oras/internal/handler/metadata"
"oras.land/oras/cmd/oras/internal/handler/metadata/model"
"oras.land/oras/cmd/oras/internal/option"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import (

ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"oras.land/oras-go/v2/content"
"oras.land/oras/cmd/oras/internal/display/metadata"
"oras.land/oras/cmd/oras/internal/display/metadata/model"
"oras.land/oras/cmd/oras/internal/handler/metadata"
"oras.land/oras/cmd/oras/internal/handler/metadata/model"
)

// discoverHandler handles json metadata output for discover events.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import (
"io"

ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"oras.land/oras/cmd/oras/internal/display/metadata"
"oras.land/oras/cmd/oras/internal/display/metadata/model"
"oras.land/oras/cmd/oras/internal/handler/metadata"
"oras.land/oras/cmd/oras/internal/handler/metadata/model"
)

// manifestFetchHandler handles JSON metadata output for manifest fetch events.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import (
"io"

ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"oras.land/oras/cmd/oras/internal/display/metadata"
"oras.land/oras/cmd/oras/internal/display/metadata/model"
"oras.land/oras/cmd/oras/internal/handler/metadata"
"oras.land/oras/cmd/oras/internal/handler/metadata/model"
"oras.land/oras/cmd/oras/internal/option"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import (
"io"

ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"oras.land/oras/cmd/oras/internal/display/metadata"
"oras.land/oras/cmd/oras/internal/display/metadata/model"
"oras.land/oras/cmd/oras/internal/handler/metadata"
"oras.land/oras/cmd/oras/internal/handler/metadata/model"
"oras.land/oras/cmd/oras/internal/option"
"oras.land/oras/internal/contentutil"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"text/template"

"github.com/Masterminds/sprig/v3"
"oras.land/oras/cmd/oras/internal/display/utils"
"oras.land/oras/cmd/oras/internal/handler/utils"
)

func parseAndWrite(out io.Writer, object any, templateStr string) error {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"strings"

ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"oras.land/oras/cmd/oras/internal/display/metadata"
"oras.land/oras/cmd/oras/internal/handler/metadata"
"oras.land/oras/cmd/oras/internal/option"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"sync/atomic"

ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"oras.land/oras/cmd/oras/internal/display/metadata"
"oras.land/oras/cmd/oras/internal/handler/metadata"
"oras.land/oras/cmd/oras/internal/option"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"sync"

ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"oras.land/oras/cmd/oras/internal/display/metadata"
"oras.land/oras/cmd/oras/internal/handler/metadata"
"oras.land/oras/cmd/oras/internal/option"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"github.com/opencontainers/go-digest"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"gopkg.in/yaml.v3"
"oras.land/oras/cmd/oras/internal/display/metadata"
"oras.land/oras/cmd/oras/internal/handler/metadata"
"oras.land/oras/internal/tree"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ limitations under the License.
package status

import (
"oras.land/oras/cmd/oras/internal/display"
"os"
"sync"

Expand Down Expand Up @@ -54,9 +55,9 @@ func NewTagStatusPrinter(target oras.Target) oras.Target {

// printer is used by the code being deprecated. Related functions should be
// removed when no-longer referenced.
var printer = NewPrinter(os.Stdout)
var printer = display.NewPrinter(os.Stdout)

// Print objects to display concurrent-safely.
// Print objects to handler concurrent-safely.
func Print(a ...any) error {
return printer.Println(a...)
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package status
import (
"context"
"io"
"oras.land/oras/cmd/oras/internal/display"
"sync"

ocispec "github.com/opencontainers/image-spec/specs-go/v1"
Expand All @@ -28,14 +29,14 @@ import (
// TextPushHandler handles text status output for push events.
type TextPushHandler struct {
verbose bool
printer *Printer
printer *display.Printer
}

// NewTextPushHandler returns a new handler for push command.
func NewTextPushHandler(out io.Writer, verbose bool) PushHandler {
return &TextPushHandler{
verbose: verbose,
printer: NewPrinter(out),
printer: display.NewPrinter(out),
}
}

Expand Down Expand Up @@ -75,7 +76,7 @@ func (ph *TextPushHandler) UpdateCopyOptions(opts *oras.CopyGraphOptions, fetche
}
opts.PostCopy = func(ctx context.Context, desc ocispec.Descriptor) error {
committed.Store(desc.Digest.String(), desc.Annotations[ocispec.AnnotationTitle])
if err := PrintSuccessorStatus(ctx, desc, fetcher, committed, ph.printer.StatusPrinter(promptSkipped, ph.verbose)); err != nil {
if err := display.PrintSuccessorStatus(ctx, desc, fetcher, committed, ph.printer.StatusPrinter(promptSkipped, ph.verbose)); err != nil {
return err
}
return ph.printer.PrintStatus(desc, promptUploaded, ph.verbose)
Expand All @@ -90,7 +91,7 @@ func NewTextAttachHandler(out io.Writer, verbose bool) AttachHandler {
// TextPullHandler handles text status output for pull events.
type TextPullHandler struct {
verbose bool
printer *Printer
printer *display.Printer
}

// TrackTarget implements PullHander.
Expand Down Expand Up @@ -127,6 +128,6 @@ func (ph *TextPullHandler) OnNodeSkipped(desc ocispec.Descriptor) error {
func NewTextPullHandler(out io.Writer, verbose bool) PullHandler {
return &TextPullHandler{
verbose: verbose,
printer: NewPrinter(out),
printer: display.NewPrinter(out),
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ package track

import (
"io"
"oras.land/oras/cmd/oras/internal/display/progress"
"os"

ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"oras.land/oras/cmd/oras/internal/display/status/progress"
)

type reader struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ package track
import (
"context"
"io"
"oras.land/oras/cmd/oras/internal/display/progress"
"os"

ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"oras.land/oras-go/v2"
"oras.land/oras-go/v2/registry"
"oras.land/oras/cmd/oras/internal/display/status/progress"
)

// GraphTarget is a tracked oras.GraphTarget.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
"oras.land/oras-go/v2"
"oras.land/oras-go/v2/content/memory"
"oras.land/oras-go/v2/registry/remote"
"oras.land/oras/cmd/oras/internal/display/status/console/testutils"
"oras.land/oras/cmd/oras/internal/display/console/testutils"
)

type testReferenceGraphTarget struct {
Expand Down
Loading

0 comments on commit 356b00b

Please sign in to comment.