Skip to content

Commit

Permalink
crane: support --full-ref for crane ls (#1525)
Browse files Browse the repository at this point in the history
* crane: support --full-ref for crane ls

* generate docs
  • Loading branch information
imjasonh authored Jan 10, 2023
1 parent b063f6a commit 5ad0a76
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
17 changes: 15 additions & 2 deletions cmd/crane/cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ import (
"fmt"

"github.com/google/go-containerregistry/pkg/crane"
"github.com/google/go-containerregistry/pkg/name"
"github.com/spf13/cobra"
)

// NewCmdList creates a new cobra.Command for the ls subcommand.
func NewCmdList(options *[]crane.Option) *cobra.Command {
return &cobra.Command{
var fullRef bool
cmd := &cobra.Command{
Use: "ls REPO",
Short: "List the tags in a repo",
Args: cobra.ExactArgs(1),
Expand All @@ -34,10 +36,21 @@ func NewCmdList(options *[]crane.Option) *cobra.Command {
return fmt.Errorf("reading tags for %s: %w", repo, err)
}

r, err := name.NewRepository(repo)
if err != nil {
return err
}

for _, tag := range tags {
fmt.Println(tag)
if fullRef {
fmt.Println(r.Tag(tag))
} else {
fmt.Println(tag)
}
}
return nil
},
}
cmd.Flags().BoolVar(&fullRef, "full-ref", false, "(Optional) if true, print the full image reference")
return cmd
}
3 changes: 2 additions & 1 deletion cmd/crane/doc/crane_ls.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5ad0a76

Please sign in to comment.