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.
This commit is contained in:
Mike Pountney
2015-12-31 12:03:22 -08:00
parent 8645ef11f1
commit a92a93b282
2 changed files with 8 additions and 1 deletions
+4
View File
@@ -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 {
+4 -1
View File
@@ -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
}