Skip to content
This repository has been archived by the owner on Sep 19, 2022. It is now read-only.

Commit

Permalink
feat: add klogs flags as persistent flags
Browse files Browse the repository at this point in the history
Adds the klog flags to the PersistentFlags of the kubetnl command.
Logging can be controlled via flags now.
  • Loading branch information
fischor committed Sep 4, 2021
1 parent 478578a commit a9572d3
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions internal/command/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"github.com/fischor/kubetnl/internal/command/version"
"github.com/spf13/cobra"
"k8s.io/cli-runtime/pkg/genericclioptions"
cliflag "k8s.io/component-base/cli/flag"
"k8s.io/klog/v2"
cmdutil "k8s.io/kubectl/pkg/cmd/util"
"k8s.io/kubectl/pkg/util/templates"
)
Expand All @@ -33,6 +35,11 @@ func NewKubetnlCommand(in io.Reader, out, err io.Writer) *cobra.Command {
},
}

// Normalize flags that use "_" as word separators to using "-". E.g.
// the flags for klog.
cmd.PersistentFlags().SetNormalizeFunc(cliflag.WarnWordSepNormalizeFunc)
cmd.PersistentFlags().SetNormalizeFunc(cliflag.WordSepNormalizeFunc)

// Adds the following global flags:
//
// "kubeconfig" "cluster" "user" "context" "namespace" "server"
Expand All @@ -44,6 +51,8 @@ func NewKubetnlCommand(in io.Reader, out, err io.Writer) *cobra.Command {
// These flags are used by the cmdutil.Factory.
kubeConfigFlags := genericclioptions.NewConfigFlags(true)
kubeConfigFlags.AddFlags(cmd.PersistentFlags())

klog.InitFlags(flag.CommandLine)
cmd.PersistentFlags().AddGoFlagSet(flag.CommandLine)

f := cmdutil.NewFactory(kubeConfigFlags)
Expand Down

0 comments on commit a9572d3

Please sign in to comment.