Skip to content

Commit

Permalink
Merge pull request #115 from marks-hats/klog-args
Browse files Browse the repository at this point in the history
Integrate klog flags with Cobra
  • Loading branch information
gmeghnag authored Sep 6, 2023
2 parents 4b2aac7 + fe5c54f commit 2bd83f1
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion root/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ import (
"github.com/gmeghnag/omc/vars"

"github.com/spf13/cobra"

"github.com/spf13/viper"

goflags "flag"
"k8s.io/klog/v2"
)

// RootCmd represents the base command when called without any subcommands
Expand All @@ -61,6 +63,19 @@ func init() {
//fmt.Println("inside init") //FLOW 0
cobra.OnInitialize(initConfig)

// add klog flags, but hide them from the overall --help information
fs := goflags.NewFlagSet("klog", goflags.ExitOnError)
klog.InitFlags(fs)
RootCmd.PersistentFlags().AddGoFlagSet(fs)
for _, f := range []string{"alsologtostderr", "log_backtrace_at", "log_dir", "log_file", "log_file_max_size", "logtostderr", "one_output", "skip_headers", "skip_log_headers", "stderrthreshold", "vmodule", "add_dir_header"} {
flag := RootCmd.PersistentFlags().Lookup(f)
if flag != nil {
flag.Hidden = true
} else {
fmt.Fprintln(os.Stderr, "Failed to find flag to remove "+f)
}
}

// Here you will define your flags and configuration settings.
// Cobra supports persistent flags, which, if defined here,
// will be global for your application.
Expand Down

0 comments on commit 2bd83f1

Please sign in to comment.