Move warning handler from `main()` to `RestConfig()` (#1359)

* Move warning handler from main() to RestConfig()

* Add also original code comment
This commit is contained in:
David Simansky 2021-06-30 16:10:10 +02:00 committed by GitHub
parent 0bbb3ec9d9
commit a90595961f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 13 deletions

View File

@ -24,8 +24,6 @@ import (
"time"
"github.com/spf13/cobra"
"k8s.io/client-go/rest"
"knative.dev/client/pkg/kn/config"
"knative.dev/client/pkg/kn/plugin"
"knative.dev/client/pkg/kn/root"
@ -36,14 +34,6 @@ func init() {
}
func main() {
// Override client-go's warning handler to give us nicely printed warnings.
rest.SetDefaultWarningHandler(
rest.NewWarningWriter(os.Stderr, rest.WarningWriterOptions{
// only print a given warning the first time we receive it
Deduplicate: true,
}),
)
os.Exit(runWithExit(os.Args[1:]))
}

View File

@ -192,10 +192,13 @@ func (params *KnParams) RestConfig() (*rest.Config, error) {
return nil, knerrors.GetError(err)
}
if params.LogHTTP {
// TODO: When we update to the newer version of client-go, replace with
// config.Wrap() for future compat.
config.WrapTransport = util.NewLoggingTransport
config.Wrap(util.NewLoggingTransport)
}
// Override client-go's warning handler to give us nicely printed warnings.
config.WarningHandler = rest.NewWarningWriter(os.Stderr, rest.WarningWriterOptions{
// only print a given warning the first time we receive it
Deduplicate: true,
})
return config, nil
}