diff --git a/cmd/ko/main.go b/cmd/ko/main.go index 7cf1b86afb..022800fce4 100644 --- a/cmd/ko/main.go +++ b/cmd/ko/main.go @@ -20,9 +20,7 @@ package main import ( "log" - "os" - "github.com/google/go-containerregistry/pkg/logs" "github.com/google/ko/pkg/commands" ) @@ -36,9 +34,6 @@ For more information see: ` func main() { - logs.Warn.SetOutput(os.Stderr) - logs.Progress.SetOutput(os.Stderr) - log.Print(Deprecation258) if err := commands.Root.Execute(); err != nil { diff --git a/doc/ko.md b/doc/ko.md index 40c6099fdb..2907634f5a 100644 --- a/doc/ko.md +++ b/doc/ko.md @@ -9,7 +9,8 @@ ko [flags] ### Options ``` - -h, --help help for ko + -h, --help help for ko + -v, --verbose Enable debug logs ``` ### SEE ALSO diff --git a/doc/ko_apply.md b/doc/ko_apply.md index 3096f39ac3..94eca33dc9 100644 --- a/doc/ko_apply.md +++ b/doc/ko_apply.md @@ -86,6 +86,12 @@ ko apply -f FILENAME [flags] -W, --watch Continuously monitor the transitive dependencies of the passed yaml files, and redeploy whenever anything changes. (DEPRECATED) ``` +### Options inherited from parent commands + +``` + -v, --verbose Enable debug logs +``` + ### SEE ALSO * [ko](ko.md) - Rapidly iterate with Go, Containers, and Kubernetes. diff --git a/doc/ko_build.md b/doc/ko_build.md index f4f2d6afb0..cee5b5f40c 100644 --- a/doc/ko_build.md +++ b/doc/ko_build.md @@ -62,6 +62,12 @@ ko build IMPORTPATH... [flags] --tarball string File to save images tarballs ``` +### Options inherited from parent commands + +``` + -v, --verbose Enable debug logs +``` + ### SEE ALSO * [ko](ko.md) - Rapidly iterate with Go, Containers, and Kubernetes. diff --git a/doc/ko_create.md b/doc/ko_create.md index d340f656ee..e49656b78a 100644 --- a/doc/ko_create.md +++ b/doc/ko_create.md @@ -86,6 +86,12 @@ ko create -f FILENAME [flags] -W, --watch Continuously monitor the transitive dependencies of the passed yaml files, and redeploy whenever anything changes. (DEPRECATED) ``` +### Options inherited from parent commands + +``` + -v, --verbose Enable debug logs +``` + ### SEE ALSO * [ko](ko.md) - Rapidly iterate with Go, Containers, and Kubernetes. diff --git a/doc/ko_delete.md b/doc/ko_delete.md index f97e753b57..be7d927f2c 100644 --- a/doc/ko_delete.md +++ b/doc/ko_delete.md @@ -12,6 +12,12 @@ ko delete [flags] -h, --help help for delete ``` +### Options inherited from parent commands + +``` + -v, --verbose Enable debug logs +``` + ### SEE ALSO * [ko](ko.md) - Rapidly iterate with Go, Containers, and Kubernetes. diff --git a/doc/ko_deps.md b/doc/ko_deps.md index 424def55c8..5dd9d5f518 100644 --- a/doc/ko_deps.md +++ b/doc/ko_deps.md @@ -27,6 +27,12 @@ ko deps IMAGE [flags] --sbom string Format for SBOM output (supports: spdx, go.version-m). (default "spdx") ``` +### Options inherited from parent commands + +``` + -v, --verbose Enable debug logs +``` + ### SEE ALSO * [ko](ko.md) - Rapidly iterate with Go, Containers, and Kubernetes. diff --git a/doc/ko_login.md b/doc/ko_login.md index 3ed4ee24c3..88cbb5546e 100644 --- a/doc/ko_login.md +++ b/doc/ko_login.md @@ -22,6 +22,12 @@ ko login [OPTIONS] [SERVER] [flags] -u, --username string Username ``` +### Options inherited from parent commands + +``` + -v, --verbose Enable debug logs +``` + ### SEE ALSO * [ko](ko.md) - Rapidly iterate with Go, Containers, and Kubernetes. diff --git a/doc/ko_resolve.md b/doc/ko_resolve.md index 35f9fcdda0..7b9e770994 100644 --- a/doc/ko_resolve.md +++ b/doc/ko_resolve.md @@ -61,6 +61,12 @@ ko resolve -f FILENAME [flags] -W, --watch Continuously monitor the transitive dependencies of the passed yaml files, and redeploy whenever anything changes. (DEPRECATED) ``` +### Options inherited from parent commands + +``` + -v, --verbose Enable debug logs +``` + ### SEE ALSO * [ko](ko.md) - Rapidly iterate with Go, Containers, and Kubernetes. diff --git a/doc/ko_run.md b/doc/ko_run.md index d8ccff478a..02b08d5923 100644 --- a/doc/ko_run.md +++ b/doc/ko_run.md @@ -49,6 +49,12 @@ ko run IMPORTPATH [flags] --tarball string File to save images tarballs ``` +### Options inherited from parent commands + +``` + -v, --verbose Enable debug logs +``` + ### SEE ALSO * [ko](ko.md) - Rapidly iterate with Go, Containers, and Kubernetes. diff --git a/doc/ko_version.md b/doc/ko_version.md index 2292828d9f..36a459a4a0 100644 --- a/doc/ko_version.md +++ b/doc/ko_version.md @@ -12,6 +12,12 @@ ko version [flags] -h, --help help for version ``` +### Options inherited from parent commands + +``` + -v, --verbose Enable debug logs +``` + ### SEE ALSO * [ko](ko.md) - Rapidly iterate with Go, Containers, and Kubernetes. diff --git a/main.go b/main.go index 43d70b664a..bad1da750f 100644 --- a/main.go +++ b/main.go @@ -22,14 +22,10 @@ import ( "os" "os/signal" - "github.com/google/go-containerregistry/pkg/logs" "github.com/google/ko/pkg/commands" ) func main() { - logs.Warn.SetOutput(os.Stderr) - logs.Progress.SetOutput(os.Stderr) - ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt) defer stop() if err := commands.Root.ExecuteContext(ctx); err != nil { diff --git a/pkg/commands/root.go b/pkg/commands/root.go index c0f4d4d6b9..a2d72807e4 100644 --- a/pkg/commands/root.go +++ b/pkg/commands/root.go @@ -15,22 +15,35 @@ package commands import ( + "os" + cranecmd "github.com/google/go-containerregistry/cmd/crane/cmd" + "github.com/google/go-containerregistry/pkg/logs" "github.com/spf13/cobra" ) var Root = New() func New() *cobra.Command { + var verbose bool root := &cobra.Command{ Use: "ko", Short: "Rapidly iterate with Go, Containers, and Kubernetes.", SilenceUsage: true, // Don't show usage on errors DisableAutoGenTag: true, + PersistentPreRun: func(cmd *cobra.Command, args []string) { + if verbose { + logs.Warn.SetOutput(os.Stderr) + logs.Debug.SetOutput(os.Stderr) + } + logs.Progress.SetOutput(os.Stderr) + }, Run: func(cmd *cobra.Command, args []string) { cmd.Help() }, } + root.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "Enable debug logs") + AddKubeCommands(root) // Also add the auth group from crane to facilitate logging into a