Skip to content

physcat/klog-cobra

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Using klog in a cobra application

Cobra uses pflags but the klog pkg forces the use of the standard go flags system.

This is a quick example how to configure klog to work with a cobra application.

Basic updates:

 import (
        "os"
 
+       goflags "flag"
+
        "github.com/spf13/cobra"
+       "k8s.io/klog/v2"
 func init() {
+       fs := goflags.NewFlagSet("", goflags.PanicOnError)
+       klog.InitFlags(fs)
+       rootCmd.Flags().AddGoFlagSet(fs)
+

Read the documentation (source code) for further details.

About

Using klog in a cobra application

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages