Skip to content

Commit 353a117

Browse files
crane: add catalog argument use annotation (#1473)
* crane: add catalog argument use annotation * crane: catalog examples and syntex update * Update cmd/crane/cmd/catalog.go Co-authored-by: Jason Hall <[email protected]> * crane: update docs for catalog * crane: fix doc generation with args Co-authored-by: Jason Hall <[email protected]>
1 parent 1711cef commit 353a117

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

cmd/crane/cmd/catalog.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,28 @@ package cmd
1616

1717
import (
1818
"fmt"
19+
"os"
20+
"strings"
1921

2022
"github.com/google/go-containerregistry/pkg/crane"
2123
"github.com/spf13/cobra"
2224
)
2325

2426
// NewCmdCatalog creates a new cobra.Command for the repos subcommand.
25-
func NewCmdCatalog(options *[]crane.Option) *cobra.Command {
27+
func NewCmdCatalog(options *[]crane.Option, argv ...string) *cobra.Command {
28+
if len(argv) == 0 {
29+
argv = []string{os.Args[0]}
30+
}
31+
32+
baseCmd := strings.Join(argv, " ")
33+
eg := fmt.Sprintf(` # list the repos for reg.example.com
34+
$ %s catalog reg.example.com`, baseCmd)
35+
2636
return &cobra.Command{
27-
Use: "catalog",
28-
Short: "List the repos in a registry",
29-
Args: cobra.ExactArgs(1),
37+
Use: "catalog [REGISTRY]",
38+
Short: "List the repos in a registry",
39+
Example: eg,
40+
Args: cobra.ExactArgs(1),
3041
RunE: func(_ *cobra.Command, args []string) error {
3142
reg := args[0]
3243
repos, err := crane.Catalog(reg, *options...)

cmd/crane/cmd/root.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func New(use, short string, options []crane.Option) *cobra.Command {
9696
NewCmdAppend(&options),
9797
NewCmdAuth(options, "crane", "auth"),
9898
NewCmdBlob(&options),
99-
NewCmdCatalog(&options),
99+
NewCmdCatalog(&options, "crane"),
100100
NewCmdConfig(&options),
101101
NewCmdCopy(&options),
102102
NewCmdDelete(&options),

cmd/crane/doc/crane_catalog.md

Lines changed: 8 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)