From 8cde8e27bb1f24484397c1ebfe1eb9279b8b80c2 Mon Sep 17 00:00:00 2001 From: Mikael Berthe Date: Sat, 7 Apr 2018 12:54:47 +0200 Subject: [PATCH] Use a list of releases in the template printer This makes the template output more flexible; e.g. it is possible to display only the first item of a release list (i.e. the latest release of a project) if there are more than one with "{{with index . 0}}"... --- gh/printer/templateprinter.go | 22 ++++++++++------------ ghreleasechecker.yaml | 2 +- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/gh/printer/templateprinter.go b/gh/printer/templateprinter.go index 16d04f7..a970ec4 100644 --- a/gh/printer/templateprinter.go +++ b/gh/printer/templateprinter.go @@ -74,18 +74,16 @@ func (p *TemplatePrinter) PrintReleases(rr []gh.ReleaseList) error { } for _, rl := range rr { - for _, r := range rl { - data, err := json.Marshal(r) - if err != nil { - return err - } - out := map[string]interface{}{} - if err := json.Unmarshal(data, &out); err != nil { - return err - } - if err = p.safeExecute(os.Stdout, out); err != nil { - return fmt.Errorf("error executing template %q: %v", p.rawTemplate, err) - } + data, err := json.Marshal(rl) + if err != nil { + return err + } + out := []map[string]interface{}{} + if err := json.Unmarshal(data, &out); err != nil { + return err + } + if err = p.safeExecute(os.Stdout, out); err != nil { + return fmt.Errorf("error executing template %q: %v", p.rawTemplate, err) } } return nil diff --git a/ghreleasechecker.yaml b/ghreleasechecker.yaml index 03fa5ad..bd2b9e0 100644 --- a/ghreleasechecker.yaml +++ b/ghreleasechecker.yaml @@ -28,5 +28,5 @@ printer: show_body: false template_printer: color_mode: 'auto' - template: '{{color ",,bold"}}{{.repo}}{{color "reset"}} {{color "red"}}{{.version}}{{color "reset"}} {{.tag}} {{.publish_date | tolocal}}{{"\n"}}' + template: '{{range .}}{{color ",,bold"}}{{.repo}}{{color "reset"}} {{color "red"}}{{.version}}{{color "reset"}} {{.tag}} {{.publish_date | tolocal}}{{"\n"}}{{end}}' ...