PrintHelp prints the help message for the given component, identified by its name. When name is '*' it shows the help messages for all components. The help message includes the component's description as well as the help messages for all component's configuration keys. An example of usage is: var
(w io.Writer, name string, comp Components, format HelpFormat)
| 49 | // Listener | string | | Host:Port to bind to |
| 50 | // ---------------------------------------------------------------------------------------------------- |
| 51 | func PrintHelp(w io.Writer, name string, comp Components, format HelpFormat) error { |
| 52 | dumpall := name == "*" |
| 53 | |
| 54 | generateHelp := GenerateTextHelp |
| 55 | if format == HelpFormatMarkdown { |
| 56 | generateHelp = GenerateMarkdownHelp |
| 57 | } |
| 58 | |
| 59 | for _, inp := range comp.Inputs { |
| 60 | if strings.EqualFold(inp.Name, name) || dumpall { |
| 61 | if err := generateHelp(w, inp); err != nil { |
| 62 | return fmt.Errorf("can't print help for %q input: %v", inp.Name, err) |
| 63 | } |
| 64 | if !dumpall { |
| 65 | return nil |
| 66 | } |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | for _, fil := range comp.Filters { |
| 71 | if strings.EqualFold(fil.Name, name) || dumpall { |
| 72 | if err := generateHelp(w, fil); err != nil { |
| 73 | return fmt.Errorf("can't print help for %q filter: %v", fil.Name, err) |
| 74 | } |
| 75 | if !dumpall { |
| 76 | return nil |
| 77 | } |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | for _, out := range comp.Outputs { |
| 82 | if strings.EqualFold(out.Name, name) || dumpall { |
| 83 | if strings.EqualFold(out.Name, name) || dumpall { |
| 84 | if err := generateHelp(w, out); err != nil { |
| 85 | return fmt.Errorf("can't print help for %q output: %v", out.Name, err) |
| 86 | } |
| 87 | if !dumpall { |
| 88 | return nil |
| 89 | } |
| 90 | } |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | for _, upl := range comp.Uploads { |
| 95 | if strings.EqualFold(upl.Name, name) || dumpall { |
| 96 | if strings.EqualFold(upl.Name, name) || dumpall { |
| 97 | if err := generateHelp(w, upl); err != nil { |
| 98 | return fmt.Errorf("can't print help for %q upload: %v", upl.Name, err) |
| 99 | } |
| 100 | if !dumpall { |
| 101 | return nil |
| 102 | } |
| 103 | } |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | if !dumpall { |
| 108 | return fmt.Errorf("component not found: %s", name) |
no outgoing calls