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

crane: Add "did you mean" to ls and catalog #2004

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions cmd/crane/cmd/catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ import (
"context"
"fmt"
"io"
"os"
"path"

"github.com/google/go-containerregistry/pkg/crane"
"github.com/google/go-containerregistry/pkg/logs"
"github.com/google/go-containerregistry/pkg/name"
"github.com/google/go-containerregistry/pkg/v1/remote"
"github.com/spf13/cobra"
Expand All @@ -47,6 +49,9 @@ func NewCmdCatalog(options *[]crane.Option, _ ...string) *cobra.Command {
func catalog(ctx context.Context, w io.Writer, src string, fullRef bool, o crane.Options) error {
reg, err := name.NewRegistry(src, o.Name...)
if err != nil {
if repo, err := name.NewRepository(src, o.Name...); err == nil {
logs.Warn.Printf("did you mean '%s catalog %s'?", os.Args[0], repo.RegistryStr())
}
return fmt.Errorf("parsing reg %q: %w", src, err)
}

Expand Down
8 changes: 8 additions & 0 deletions cmd/crane/cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ import (
"context"
"fmt"
"io"
"os"
"strings"

"github.com/google/go-containerregistry/pkg/crane"
"github.com/google/go-containerregistry/pkg/logs"
"github.com/google/go-containerregistry/pkg/name"
"github.com/google/go-containerregistry/pkg/v1/remote"
"github.com/spf13/cobra"
Expand All @@ -47,6 +49,9 @@ func NewCmdList(options *[]crane.Option) *cobra.Command {
func list(ctx context.Context, w io.Writer, src string, fullRef, omitDigestTags bool, o crane.Options) error {
repo, err := name.NewRepository(src, o.Name...)
if err != nil {
if _, err := name.NewRegistry(src, o.Name...); err == nil {
logs.Warn.Printf("did you mean '%s catalog %s'?", os.Args[0], src)
}
return fmt.Errorf("parsing repo %q: %w", src, err)
}

Expand All @@ -57,6 +62,9 @@ func list(ctx context.Context, w io.Writer, src string, fullRef, omitDigestTags

lister, err := puller.Lister(ctx, repo)
if err != nil {
if _, err := name.NewRegistry(src, o.Name...); err == nil {
logs.Warn.Printf("did you mean '%s catalog %s'?", os.Args[0], src)
}
return fmt.Errorf("reading tags for %s: %w", repo, err)
}

Expand Down
Loading