Skip to content

Commit

Permalink
core: Add plugin option to always force verbose output
Browse files Browse the repository at this point in the history
  • Loading branch information
ppmathis committed May 29, 2019
1 parent 8d7eb9f commit fc90c37
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions nagocheck/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type basePlugin struct {
module Module
useDefaultFlags bool
useDefaultThresholds bool
forceVerboseOutput bool

verboseOutput bool
warningThreshold nagopher.OptionalBounds
Expand All @@ -60,6 +61,7 @@ func NewPlugin(name string, options ...PluginOpt) Plugin {
description: name,
useDefaultFlags: true,
useDefaultThresholds: true,
forceVerboseOutput: false,
}

for _, option := range options {
Expand All @@ -76,6 +78,13 @@ func PluginDescription(description string) PluginOpt {
}
}

// PluginForceVerbose is a functional option for NewPlugin(), which toggles forcing verbose check output
func PluginForceVerbose(enabled bool) PluginOpt {
return func(p *basePlugin) {
p.forceVerboseOutput = enabled
}
}

// PluginDefaultFlags is a functional option for NewPlugin(), which toggles the definition of default flags
func PluginDefaultFlags(enabled bool) PluginOpt {
return func(p *basePlugin) {
Expand All @@ -92,8 +101,10 @@ func PluginDefaultThresholds(enabled bool) PluginOpt {

func (p *basePlugin) defineDefaultFlags(node KingpinNode) {
if p.useDefaultFlags {
node.Flag("verbose", "Enable verbose plugin output.").
Short('v').BoolVar(&p.verboseOutput)
if !p.verboseOutput {
node.Flag("verbose", "Enable verbose plugin output.").
Short('v').BoolVar(&p.verboseOutput)
}
}

if p.useDefaultThresholds {
Expand Down Expand Up @@ -121,6 +132,10 @@ func (p *basePlugin) setModule(module Module) {
}

func (p *basePlugin) VerboseOutput() bool {
if p.forceVerboseOutput {
return true
}

return p.verboseOutput
}

Expand Down

0 comments on commit fc90c37

Please sign in to comment.