Skip to content

Commit

Permalink
lkar: improve commands help structure
Browse files Browse the repository at this point in the history
Signed-off-by: Adphi <philippe.adrien.nousse@gmail.com>
  • Loading branch information
Adphi committed Oct 25, 2023
1 parent cd794cd commit 7d89c0a
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 6 deletions.
11 changes: 8 additions & 3 deletions cmd/lkar/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import (
"oras.land/oras-go/v2/registry/remote/auth"
)

var authGroup = &cobra.Group{ID: "0_auth", Title: "Authentication Commands:"}

var (
passStdin bool

Expand All @@ -45,6 +47,7 @@ Log in with username and password in an interactive terminal and no TLS check:
lkar login --insecure localhost:5000
`,
Args: cobra.ExactArgs(1),
GroupID: authGroup.ID,
PreRunE: setup,
RunE: func(cmd *cobra.Command, args []string) error {
if user == "" {
Expand Down Expand Up @@ -110,9 +113,10 @@ Log in with username and password in an interactive terminal and no TLS check:
},
}
logoutCmd = &cobra.Command{
Use: "logout [repository]",
Short: "Logout from an Artifact Registry repository",
Args: cobra.ExactArgs(1),
Use: "logout [repository]",
Short: "Logout from an Artifact Registry repository",
GroupID: authGroup.ID,
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
creds, err := credsStore.Get(cmd.Context(), repoURL())
if err != nil {
Expand All @@ -129,4 +133,5 @@ Log in with username and password in an interactive terminal and no TLS check:
func init() {
loginCmd.Flags().BoolVar(&passStdin, "password-stdin", false, "Take the password from stdin")
rootCmd.AddCommand(loginCmd, logoutCmd)
rootCmd.AddGroup(authGroup)
}
6 changes: 5 additions & 1 deletion cmd/lkar/packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@ import (
"github.com/spf13/cobra"
)

var PkgGroup = &cobra.Group{ID: "2_packages", Title: "Package Commands:"}

func newPkgCmd(typ string) *cobra.Command {
pkgCmd := &cobra.Command{
Use: typ,
Short: fmt.Sprintf("Root command for %s management", typ),
Short: fmt.Sprintf("Manage %s packages", typ),
GroupID: PkgGroup.ID,
PersistentPreRunE: setup,
}
pkgCmd.AddCommand(
Expand All @@ -37,6 +40,7 @@ func newPkgCmd(typ string) *cobra.Command {
}

func init() {
rootCmd.AddGroup(PkgGroup)
for _, v := range []string{"apk", "deb", "rpm", "helm"} {
rootCmd.AddCommand(newPkgCmd(v))
}
Expand Down
4 changes: 4 additions & 0 deletions cmd/lkar/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,14 @@ import (
)

var (
repoGroup = &cobra.Group{ID: "1_repositories", Title: "Repository Commands:"}

repoCmd = &cobra.Command{
Use: "repositories [registry]",
Short: "List repositories in the registry",
Aliases: []string{"repo", "repos"},
Args: cobra.ExactArgs(1),
GroupID: repoGroup.ID,
RunE: func(cmd *cobra.Command, args []string) error {
u := urlWithType() + "/_repositories/" + repository
if repository == "" {
Expand Down Expand Up @@ -102,4 +105,5 @@ func init() {
repoCmd.PersistentFlags().StringVarP(&output, "output", "o", "table", "Output format (table, json, yaml)")
repoCmd.RegisterFlagCompletionFunc("output", completeOutput)
rootCmd.AddCommand(repoCmd)
rootCmd.AddGroup(repoGroup)
}
5 changes: 3 additions & 2 deletions cmd/lkar/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ import (

var (
cmdVersion = &cobra.Command{
Use: "version",
Use: "version",
Short: "Print the version and build date of lk-artifact-registry",
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("%s (%s)\n", artifact_registry.Version, artifact_registry.BuildDate)
fmt.Printf("%s\n%s\n", artifact_registry.Version, artifact_registry.BuildDate)
},
}
)
Expand Down
4 changes: 4 additions & 0 deletions cmd/lkard/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ var (
if tagPerArtifact {
opts = append(opts, storage.WithArtifactTags())
}
if strings.HasSuffix(backend, "docker.io") && proxyAddr == "" {
logger.C(cmd.Context()).Warnf("using docker.io as backend without proxy is not recommended")
logger.C(cmd.Context()).Warnf("the rate limit of 100 requests per 6 hours is very easy to reach using this tool")
}
if err := run(cmd.Context(), repo, opts...); err != nil {
logger.C(cmd.Context()).Fatal(err)
}
Expand Down

0 comments on commit 7d89c0a

Please sign in to comment.