From 7d89c0a198454807da3809d49e7082eaa6aed1d6 Mon Sep 17 00:00:00 2001 From: Adphi Date: Wed, 25 Oct 2023 13:45:31 +0200 Subject: [PATCH] lkar: improve commands help structure Signed-off-by: Adphi --- cmd/lkar/auth.go | 11 ++++++++--- cmd/lkar/packages.go | 6 +++++- cmd/lkar/repo.go | 4 ++++ cmd/lkar/version.go | 5 +++-- cmd/lkard/main.go | 4 ++++ 5 files changed, 24 insertions(+), 6 deletions(-) diff --git a/cmd/lkar/auth.go b/cmd/lkar/auth.go index 0b1a956..205c4e5 100644 --- a/cmd/lkar/auth.go +++ b/cmd/lkar/auth.go @@ -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 @@ -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 == "" { @@ -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 { @@ -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) } diff --git a/cmd/lkar/packages.go b/cmd/lkar/packages.go index e8e619b..6ca8eb2 100644 --- a/cmd/lkar/packages.go +++ b/cmd/lkar/packages.go @@ -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( @@ -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)) } diff --git a/cmd/lkar/repo.go b/cmd/lkar/repo.go index a7b9d57..095a63a 100644 --- a/cmd/lkar/repo.go +++ b/cmd/lkar/repo.go @@ -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 == "" { @@ -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) } diff --git a/cmd/lkar/version.go b/cmd/lkar/version.go index 89e7921..64a49a6 100644 --- a/cmd/lkar/version.go +++ b/cmd/lkar/version.go @@ -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) }, } ) diff --git a/cmd/lkard/main.go b/cmd/lkard/main.go index 01ae13d..8361a53 100644 --- a/cmd/lkard/main.go +++ b/cmd/lkard/main.go @@ -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) }