Support printing output with usage flag too

This commit is contained in:
Cameron Sparr 2015-10-22 14:24:51 -06:00
parent 2007064c47
commit ae7ad2230f
2 changed files with 21 additions and 4 deletions

View File

@ -62,7 +62,9 @@ func main() {
if *fUsage != "" { if *fUsage != "" {
if err := telegraf.PrintPluginConfig(*fUsage); err != nil { if err := telegraf.PrintPluginConfig(*fUsage); err != nil {
log.Fatal(err) if err2 := telegraf.PrintOutputConfig(*fUsage); err2 != nil {
log.Fatalf("%s and %s", err, err2)
}
} }
return return
} }

View File

@ -325,9 +325,14 @@ func PrintSampleConfig(pluginFilters []string, outputFilters []string) {
} }
} }
func printConfig(name string, plugin plugins.Plugin) { type printer interface {
fmt.Printf("\n# %s\n[%s]", plugin.Description(), name) Description() string
config := plugin.SampleConfig() SampleConfig() string
}
func printConfig(name string, p printer) {
fmt.Printf("\n# %s\n[%s]", p.Description(), name)
config := p.SampleConfig()
if config == "" { if config == "" {
fmt.Printf("\n # no configuration\n") fmt.Printf("\n # no configuration\n")
} else { } else {
@ -354,6 +359,16 @@ func PrintPluginConfig(name string) error {
return nil return nil
} }
// PrintOutputConfig prints the config usage of a single output.
func PrintOutputConfig(name string) error {
if creator, ok := outputs.Outputs[name]; ok {
printConfig(name, creator())
} else {
return errors.New(fmt.Sprintf("Output %s not found", name))
}
return nil
}
// Used for fuzzy matching struct field names in FieldByNameFunc calls below // Used for fuzzy matching struct field names in FieldByNameFunc calls below
func fieldMatch(field string) func(string) bool { func fieldMatch(field string) func(string) bool {
return func(name string) bool { return func(name string) bool {