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 err := telegraf.PrintPluginConfig(*fUsage); err != nil {
log.Fatal(err)
if err2 := telegraf.PrintOutputConfig(*fUsage); err2 != nil {
log.Fatalf("%s and %s", err, err2)
}
}
return
}

View File

@ -325,9 +325,14 @@ func PrintSampleConfig(pluginFilters []string, outputFilters []string) {
}
}
func printConfig(name string, plugin plugins.Plugin) {
fmt.Printf("\n# %s\n[%s]", plugin.Description(), name)
config := plugin.SampleConfig()
type printer interface {
Description() string
SampleConfig() string
}
func printConfig(name string, p printer) {
fmt.Printf("\n# %s\n[%s]", p.Description(), name)
config := p.SampleConfig()
if config == "" {
fmt.Printf("\n # no configuration\n")
} else {
@ -354,6 +359,16 @@ func PrintPluginConfig(name string) error {
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
func fieldMatch(field string) func(string) bool {
return func(name string) bool {