Skip to content

Commit 5ad0a76

Browse files
authored
crane: support --full-ref for crane ls (#1525)
* crane: support --full-ref for crane ls * generate docs
1 parent b063f6a commit 5ad0a76

2 files changed

Lines changed: 17 additions & 3 deletions

File tree

cmd/crane/cmd/list.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@ import (
1818
"fmt"
1919

2020
"github.com/google/go-containerregistry/pkg/crane"
21+
"github.com/google/go-containerregistry/pkg/name"
2122
"github.com/spf13/cobra"
2223
)
2324

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

39+
r, err := name.NewRepository(repo)
40+
if err != nil {
41+
return err
42+
}
43+
3744
for _, tag := range tags {
38-
fmt.Println(tag)
45+
if fullRef {
46+
fmt.Println(r.Tag(tag))
47+
} else {
48+
fmt.Println(tag)
49+
}
3950
}
4051
return nil
4152
},
4253
}
54+
cmd.Flags().BoolVar(&fullRef, "full-ref", false, "(Optional) if true, print the full image reference")
55+
return cmd
4356
}

cmd/crane/doc/crane_ls.md

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)