-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #139 from samanthajayasinghe/console-token
OSD-17209: Update backplane cli commands default to warning log level
- Loading branch information
Showing
4 changed files
with
91 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package main | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func TestIt(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "Root Test Suite") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package main | ||
|
||
import ( | ||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
var _ = Describe("Backplane commands", func() { | ||
Context("Test root cmd", func() { | ||
|
||
It("Check root cmd help ", func() { | ||
err := rootCmd.Help() | ||
Expect(err).To(BeNil()) | ||
}) | ||
|
||
It("Check verbosity persistent flag", func() { | ||
flagSet := rootCmd.PersistentFlags() | ||
verbosityFlag := flagSet.Lookup("verbosity") | ||
Expect(verbosityFlag).NotTo(BeNil()) | ||
|
||
// check the deafult log level | ||
Expect(verbosityFlag.DefValue).To(Equal("warning")) | ||
|
||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package globalflags | ||
|
||
import ( | ||
"strings" | ||
|
||
log "github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
type levelFlag log.Level | ||
|
||
var ( | ||
// some defaults for configuration | ||
defaultLogLevel = log.WarnLevel.String() | ||
logLevel levelFlag | ||
) | ||
|
||
// String returns log level string | ||
func (l *levelFlag) String() string { | ||
return log.Level(*l).String() | ||
} | ||
|
||
// Set updates the log level | ||
func (l *levelFlag) Set(value string) error { | ||
lvl, err := log.ParseLevel(strings.TrimSpace(value)) | ||
if err == nil { | ||
*l = levelFlag(lvl) | ||
} | ||
log.SetLevel(lvl) | ||
return err | ||
} | ||
|
||
// Type defines log level type | ||
func (l *levelFlag) Type() string { | ||
return "string" | ||
} | ||
|
||
// AddVerbosityFlag add Persistent verbosity flag | ||
func AddVerbosityFlag(cmd *cobra.Command) { | ||
// Set default log level | ||
_ = logLevel.Set(defaultLogLevel) | ||
logLevelFlag := cmd.PersistentFlags().VarPF( | ||
&logLevel, | ||
"verbosity", | ||
"v", | ||
"Verbosity level: panic, fatal, error, warn, info, debug. Providing no verbosity level will default to info.", | ||
) | ||
logLevelFlag.NoOptDefVal = log.InfoLevel.String() | ||
} |