From da6cbd502186ee806409941be5fd4aaffe52dfb2 Mon Sep 17 00:00:00 2001 From: Mike Pountney Date: Thu, 31 Dec 2015 12:03:22 -0800 Subject: [PATCH] Add exposed versions of getTemplate and runTemplate GetTemplate and RunTemplate allow external users to access the template system, and in particular allow them to provide their own Buffer to write the output to. I've implemented exposed versions calling the private functions, rather than breaking the internal API. If this isn't a concern, we should remove getTemplate and runTemplate in a future commit. --- cli.go | 4 ++++ util.go | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/cli.go b/cli.go index e5de4e9..312dfea 100644 --- a/cli.go +++ b/cli.go @@ -177,6 +177,10 @@ func (c *Cli) makeRequest(req *http.Request) (resp *http.Response, err error) { return resp, nil } +func (c *Cli) GetTemplate(name string) string { + return c.getTemplate(name) +} + func (c *Cli) getTemplate(name string) string { if override, ok := c.opts["template"].(string); ok { if _, err := os.Stat(override); err == nil { diff --git a/util.go b/util.go index 4c76c05..382e4c7 100644 --- a/util.go +++ b/util.go @@ -109,8 +109,11 @@ func dateFormat(format string, content string) (string, error) { } } -func runTemplate(templateContent string, data interface{}, out io.Writer) error { +func RunTemplate(templateContent string, data interface{}, out io.Writer) error { + return runTemplate(templateContent, data, out) +} +func runTemplate(templateContent string, data interface{}, out io.Writer) error { if out == nil { out = os.Stdout }