Use variadic options to configure Kong.

This commit is contained in:
Alec Thomas
2018-05-18 21:17:48 +10:00
parent b4b5827044
commit d03571a873
5 changed files with 128 additions and 18 deletions
+28
View File
@@ -0,0 +1,28 @@
package kong
import (
"io"
"text/template"
)
const defaultHelp = `{{- with .Application -}}
usage: {{.Name}}
{{- end -}}
`
var defaultHelpTemplate = template.Must(template.New("help").Parse(defaultHelp))
// WriteHelp to w. If w is nil, the default stdout writer will be used.
func (k *Kong) WriteHelp(w io.Writer) error {
if w == nil {
w = k.stdout
}
ctx := map[string]interface{}{
"Application": k.Model,
}
for k, v := range k.helpContext {
ctx[k] = v
}
return k.help.Execute(w, ctx)
}