Skip to content

Commit 6f96074

Browse files
leogrpoiana
authored andcommitted
refactor(cmd): improve PersistentPreRun
Signed-off-by: Leonardo Grasso <[email protected]>
1 parent 34c4afd commit 6f96074

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

cmd/install_tls_linux.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"k8s.io/cli-runtime/pkg/genericclioptions"
2424
)
2525

26+
// Defaults
2627
const (
2728
DefaultCertsCountry = "US"
2829
DefaultCertsOrg = "falcosecurity"

cmd/root.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,8 @@ func New(streams genericclioptions.IOStreams) *cobra.Command {
5353

5454
rootCmd.PersistentPreRun = func(c *cobra.Command, args []string) {
5555
// Set destination for usage and error messages
56-
rootCmd.SetOutput(streams.ErrOut)
57-
// Be fabulous
58-
if configOptions.Fabulous {
59-
logger.Fabulous = true
60-
logger.Color = false
61-
}
62-
logger.Level = configOptions.Verbose
56+
c.SetOut(streams.Out)
57+
c.SetErr(streams.ErrOut)
6358

6459
// When a flag is not provided by the user,
6560
// fallback to one of (in order of precedence):
@@ -72,6 +67,13 @@ func New(streams genericclioptions.IOStreams) *cobra.Command {
7267
c.Flags().Set(f.Name, v)
7368
}
7469
})
70+
71+
// Be fabulous
72+
if configOptions.Fabulous {
73+
logger.Fabulous = true
74+
logger.Color = false
75+
}
76+
logger.Level = configOptions.Verbose
7577
}
7678

7779
pflags := rootCmd.PersistentFlags()

0 commit comments

Comments
 (0)