Skip to content

Commit

Permalink
feat: Add klog flags to nomos cli (#1026)
Browse files Browse the repository at this point in the history
  • Loading branch information
karlkfi authored Nov 15, 2023
1 parent aa68c09 commit 56da4b0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
8 changes: 3 additions & 5 deletions cmd/nomos/bugreport/bugreport.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package bugreport

import (
"flag"
"fmt"

"github.com/pkg/errors"
Expand All @@ -42,10 +41,9 @@ var Cmd = &cobra.Command{
// Don't show usage on error, as argument validation passed.
cmd.SilenceUsage = true

// hack to set the hidden variable in klog to also print info statements
// cobra does not expose core golang-style flags
if err := flag.CommandLine.Parse([]string{"--stderrthreshold=0"}); err != nil {
klog.Errorf("could not increase logging verbosity: %v", err)
// Send all logs to STDERR.
if err := cmd.InheritedFlags().Lookup("stderrthreshold").Value.Set("0"); err != nil {
klog.Errorf("failed to increase logging STDERR threshold: %v", err)
}

cfg, err := restconfig.NewRestConfig(flags.ClientTimeout)
Expand Down
11 changes: 9 additions & 2 deletions cmd/nomos/nomos.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,15 @@ func init() {
}

func main() {
klog.InitFlags(nil)
flag.Parse()
// Use the default flag set, because some libs register flags with init.
fs := flag.CommandLine

// Register klog flags
klog.InitFlags(fs)

// Cobra uses the pflag lib, instead of the go flag lib.
// So re-register all go flags as global (aka persistent) pflags.
rootCmd.PersistentFlags().AddGoFlagSet(fs)

if err := rootCmd.Execute(); err != nil {
os.Exit(1)
Expand Down

0 comments on commit 56da4b0

Please sign in to comment.