From 449618ad855f4f25e0c67d2a3170d308d9e7f663 Mon Sep 17 00:00:00 2001 From: Thomas Boerger Date: Wed, 18 Sep 2019 22:36:14 +0200 Subject: [PATCH] Integrate funcmap for all template executions --- drone/autoscale/autoscale_version.go | 6 +++--- drone/build/build_info.go | 3 ++- drone/build/build_last.go | 3 ++- drone/build/build_list.go | 3 ++- drone/build/build_promote.go | 3 ++- drone/build/build_start.go | 3 ++- drone/cron/cron_info.go | 4 ++-- drone/cron/cron_list.go | 19 ++++--------------- drone/info/info.go | 6 +++--- drone/node/node_create.go | 4 ++-- drone/node/node_import.go | 4 ++-- drone/node/node_import_all.go | 4 ++-- drone/node/node_info.go | 4 ++-- drone/node/node_list.go | 6 +++--- drone/orgsecret/secret_info.go | 6 +++--- drone/orgsecret/secret_list.go | 6 +++--- drone/plugins/registry/list.go | 4 ++-- drone/queue/queue_list.go | 3 ++- drone/repo/repo_info.go | 3 ++- drone/repo/repo_list.go | 3 ++- drone/repo/repo_sync.go | 3 ++- drone/secret/secret_info.go | 6 +++--- drone/secret/secret_list.go | 6 +++--- drone/server/server_create.go | 6 +++--- drone/server/server_destroy.go | 6 +++--- drone/server/server_env.go | 6 +++--- drone/server/server_info.go | 6 +++--- drone/server/server_list.go | 6 +++--- drone/user/user_info.go | 6 +++--- drone/user/user_list.go | 6 +++--- 30 files changed, 76 insertions(+), 78 deletions(-) diff --git a/drone/autoscale/autoscale_version.go b/drone/autoscale/autoscale_version.go index 0be0a1f..96bfe8b 100644 --- a/drone/autoscale/autoscale_version.go +++ b/drone/autoscale/autoscale_version.go @@ -4,9 +4,9 @@ import ( "os" "text/template" - "github.com/urfave/cli" - "github.com/drone/drone-cli/drone/internal" + "github.com/drone/funcmap" + "github.com/urfave/cli" ) var autoscaleVersionCmd = cli.Command{ @@ -33,7 +33,7 @@ func autoscaleVersion(c *cli.Context) error { return err } - tmpl, err := template.New("_").Parse(c.String("format") + "\n") + tmpl, err := template.New("_").Funcs(funcmap.Funcs).Parse(c.String("format") + "\n") if err != nil { return err } diff --git a/drone/build/build_info.go b/drone/build/build_info.go index 919f763..0f76933 100644 --- a/drone/build/build_info.go +++ b/drone/build/build_info.go @@ -6,6 +6,7 @@ import ( "text/template" "github.com/drone/drone-cli/drone/internal" + "github.com/drone/funcmap" "github.com/urfave/cli" ) @@ -56,7 +57,7 @@ func buildInfo(c *cli.Context) error { return err } - tmpl, err := template.New("_").Parse(c.String("format")) + tmpl, err := template.New("_").Funcs(funcmap.Funcs).Parse(c.String("format")) if err != nil { return err } diff --git a/drone/build/build_last.go b/drone/build/build_last.go index 6d9b3f5..c380dff 100644 --- a/drone/build/build_last.go +++ b/drone/build/build_last.go @@ -5,6 +5,7 @@ import ( "text/template" "github.com/drone/drone-cli/drone/internal" + "github.com/drone/funcmap" "github.com/urfave/cli" ) @@ -44,7 +45,7 @@ func buildLast(c *cli.Context) error { return err } - tmpl, err := template.New("_").Parse(c.String("format")) + tmpl, err := template.New("_").Funcs(funcmap.Funcs).Parse(c.String("format")) if err != nil { return err } diff --git a/drone/build/build_list.go b/drone/build/build_list.go index e85d17c..48ed5d1 100644 --- a/drone/build/build_list.go +++ b/drone/build/build_list.go @@ -6,6 +6,7 @@ import ( "github.com/drone/drone-cli/drone/internal" "github.com/drone/drone-go/drone" + "github.com/drone/funcmap" "github.com/urfave/cli" ) @@ -62,7 +63,7 @@ func buildList(c *cli.Context) error { return err } - tmpl, err := template.New("_").Parse(c.String("format") + "\n") + tmpl, err := template.New("_").Funcs(funcmap.Funcs).Parse(c.String("format") + "\n") if err != nil { return err } diff --git a/drone/build/build_promote.go b/drone/build/build_promote.go index 6838562..51b187f 100644 --- a/drone/build/build_promote.go +++ b/drone/build/build_promote.go @@ -6,6 +6,7 @@ import ( "text/template" "github.com/drone/drone-cli/drone/internal" + "github.com/drone/funcmap" "github.com/urfave/cli" ) @@ -50,7 +51,7 @@ func buildPromote(c *cli.Context) (err error) { return err } - tmpl, err := template.New("_").Parse(c.String("format")) + tmpl, err := template.New("_").Funcs(funcmap.Funcs).Parse(c.String("format")) if err != nil { return err } diff --git a/drone/build/build_start.go b/drone/build/build_start.go index 91574d6..9d25614 100644 --- a/drone/build/build_start.go +++ b/drone/build/build_start.go @@ -7,6 +7,7 @@ import ( "text/template" "github.com/drone/drone-cli/drone/internal" + "github.com/drone/funcmap" "github.com/urfave/cli" ) @@ -66,7 +67,7 @@ func buildStart(c *cli.Context) (err error) { return err } - tmpl, err := template.New("_").Parse(c.String("format")) + tmpl, err := template.New("_").Funcs(funcmap.Funcs).Parse(c.String("format")) if err != nil { return err } diff --git a/drone/cron/cron_info.go b/drone/cron/cron_info.go index d512b50..c811911 100644 --- a/drone/cron/cron_info.go +++ b/drone/cron/cron_info.go @@ -5,7 +5,7 @@ import ( "os" "github.com/drone/drone-cli/drone/internal" - + "github.com/drone/funcmap" "github.com/urfave/cli" ) @@ -39,7 +39,7 @@ func cronInfo(c *cli.Context) error { return err } format := c.String("format") - tmpl, err := template.New("_").Funcs(funcs).Parse(format) + tmpl, err := template.New("_").Funcs(funcmap.Funcs).Parse(format) if err != nil { return err } diff --git a/drone/cron/cron_list.go b/drone/cron/cron_list.go index 3bbc3b0..bf03c27 100644 --- a/drone/cron/cron_list.go +++ b/drone/cron/cron_list.go @@ -3,11 +3,10 @@ package cron import ( "html/template" "os" - "time" - - "github.com/urfave/cli" "github.com/drone/drone-cli/drone/internal" + "github.com/drone/funcmap" + "github.com/urfave/cli" ) var cronListCmd = cli.Command{ @@ -40,7 +39,7 @@ func cronList(c *cli.Context) error { return err } format := c.String("format") + "\n" - tmpl, err := template.New("_").Funcs(funcs).Parse(format) + tmpl, err := template.New("_").Funcs(funcmap.Funcs).Parse(format) if err != nil { return err } @@ -53,18 +52,8 @@ func cronList(c *cli.Context) error { // template for build list information var tmplCronList = "\x1b[33m{{ .Name }} \x1b[0m" + ` Expr: {{ .Expr }} -Next: {{ fromUnix .Next }} +Next: {{ .Next | time }} {{- if .Disabled }} Disabled: true {{- end }} ` - -var funcs = map[string]interface{}{ - "fromUnix": func(v interface{}) string { - i, ok := v.(int64) - if !ok { - return "" - } - return time.Unix(i, 0).String() - }, -} diff --git a/drone/info/info.go b/drone/info/info.go index 5c9aa3d..58f7b54 100644 --- a/drone/info/info.go +++ b/drone/info/info.go @@ -4,9 +4,9 @@ import ( "os" "text/template" - "github.com/urfave/cli" - "github.com/drone/drone-cli/drone/internal" + "github.com/drone/funcmap" + "github.com/urfave/cli" ) // Command exports the info command. @@ -35,7 +35,7 @@ func info(c *cli.Context) error { return err } - tmpl, err := template.New("_").Parse(c.String("format") + "\n") + tmpl, err := template.New("_").Funcs(funcmap.Funcs).Parse(c.String("format") + "\n") if err != nil { return err } diff --git a/drone/node/node_create.go b/drone/node/node_create.go index 9af9965..e78eb50 100644 --- a/drone/node/node_create.go +++ b/drone/node/node_create.go @@ -7,7 +7,7 @@ import ( "github.com/drone/drone-cli/drone/internal" "github.com/drone/drone-go/drone" - + "github.com/drone/funcmap" "github.com/urfave/cli" ) @@ -141,7 +141,7 @@ func nodeCreate(c *cli.Context) error { } format := c.String("format") - tmpl, err := template.New("_").Parse(format) + tmpl, err := template.New("_").Funcs(funcmap.Funcs).Parse(format) if err != nil { return err } diff --git a/drone/node/node_import.go b/drone/node/node_import.go index 71d7872..49a0fe4 100644 --- a/drone/node/node_import.go +++ b/drone/node/node_import.go @@ -11,7 +11,7 @@ import ( "github.com/drone/drone-cli/drone/internal" "github.com/drone/drone-go/drone" - + "github.com/drone/funcmap" "github.com/urfave/cli" ) @@ -138,7 +138,7 @@ func nodeImport(c *cli.Context) error { } format := c.String("format") - tmpl, err := template.New("_").Parse(format) + tmpl, err := template.New("_").Funcs(funcmap.Funcs).Parse(format) if err != nil { return err } diff --git a/drone/node/node_import_all.go b/drone/node/node_import_all.go index fcc684b..c6de72e 100644 --- a/drone/node/node_import_all.go +++ b/drone/node/node_import_all.go @@ -10,7 +10,7 @@ import ( "github.com/drone/drone-cli/drone/internal" "github.com/drone/drone-go/drone" - + "github.com/drone/funcmap" "github.com/urfave/cli" ) @@ -78,7 +78,7 @@ func nodeImportAll(c *cli.Context) error { } format := c.String("format") + "\n" - tmpl, err := template.New("_").Parse(format) + tmpl, err := template.New("_").Funcs(funcmap.Funcs).Parse(format) if err != nil { return err } diff --git a/drone/node/node_info.go b/drone/node/node_info.go index 14a3de1..63d3548 100644 --- a/drone/node/node_info.go +++ b/drone/node/node_info.go @@ -5,7 +5,7 @@ import ( "os" "github.com/drone/drone-cli/drone/internal" - + "github.com/drone/funcmap" "github.com/urfave/cli" ) @@ -33,7 +33,7 @@ func nodeInfo(c *cli.Context) error { return err } format := c.String("format") - tmpl, err := template.New("_").Parse(format) + tmpl, err := template.New("_").Funcs(funcmap.Funcs).Parse(format) if err != nil { return err } diff --git a/drone/node/node_list.go b/drone/node/node_list.go index e9df03e..88416b6 100644 --- a/drone/node/node_list.go +++ b/drone/node/node_list.go @@ -4,9 +4,9 @@ import ( "html/template" "os" - "github.com/urfave/cli" - "github.com/drone/drone-cli/drone/internal" + "github.com/drone/funcmap" + "github.com/urfave/cli" ) var nodeListCmd = cli.Command{ @@ -32,7 +32,7 @@ func nodeList(c *cli.Context) error { return err } format := c.String("format") + "\n" - tmpl, err := template.New("_").Parse(format) + tmpl, err := template.New("_").Funcs(funcmap.Funcs).Parse(format) if err != nil { return err } diff --git a/drone/orgsecret/secret_info.go b/drone/orgsecret/secret_info.go index fb0aaae..70696ef 100644 --- a/drone/orgsecret/secret_info.go +++ b/drone/orgsecret/secret_info.go @@ -4,9 +4,9 @@ import ( "html/template" "os" - "github.com/urfave/cli" - "github.com/drone/drone-cli/drone/internal" + "github.com/drone/funcmap" + "github.com/urfave/cli" ) var secretInfoCmd = cli.Command{ @@ -37,7 +37,7 @@ func secretInfo(c *cli.Context) error { if err != nil { return err } - tmpl, err := template.New("_").Parse(format) + tmpl, err := template.New("_").Funcs(funcmap.Funcs).Parse(format) if err != nil { return err } diff --git a/drone/orgsecret/secret_list.go b/drone/orgsecret/secret_list.go index 223f04d..80460eb 100644 --- a/drone/orgsecret/secret_list.go +++ b/drone/orgsecret/secret_list.go @@ -4,10 +4,10 @@ import ( "html/template" "os" - "github.com/urfave/cli" - "github.com/drone/drone-cli/drone/internal" "github.com/drone/drone-go/drone" + "github.com/drone/funcmap" + "github.com/urfave/cli" ) var secretListCmd = cli.Command{ @@ -44,7 +44,7 @@ func secretList(c *cli.Context) error { if err != nil { return err } - tmpl, err := template.New("_").Parse(format) + tmpl, err := template.New("_").Funcs(funcmap.Funcs).Parse(format) if err != nil { return err } diff --git a/drone/plugins/registry/list.go b/drone/plugins/registry/list.go index 17a0388..7b15ce9 100644 --- a/drone/plugins/registry/list.go +++ b/drone/plugins/registry/list.go @@ -8,7 +8,7 @@ import ( "github.com/drone/drone-cli/drone/internal" "github.com/drone/drone-go/drone" "github.com/drone/drone-go/plugin/registry" - + "github.com/drone/funcmap" "github.com/urfave/cli" ) @@ -107,7 +107,7 @@ func registryList(c *cli.Context) error { } format := c.String("format") + "\n" - tmpl, err := template.New("_").Parse(format) + tmpl, err := template.New("_").Funcs(funcmap.Funcs).Parse(format) if err != nil { return err } diff --git a/drone/queue/queue_list.go b/drone/queue/queue_list.go index c502784..e7ba541 100644 --- a/drone/queue/queue_list.go +++ b/drone/queue/queue_list.go @@ -6,6 +6,7 @@ import ( "text/template" "github.com/drone/drone-cli/drone/internal" + "github.com/drone/funcmap" "github.com/urfave/cli" ) @@ -37,7 +38,7 @@ func queueList(c *cli.Context) (err error) { return nil } - tmpl, err := template.New("_").Parse(c.String("format") + "\n") + tmpl, err := template.New("_").Funcs(funcmap.Funcs).Parse(c.String("format") + "\n") if err != nil { return err } diff --git a/drone/repo/repo_info.go b/drone/repo/repo_info.go index d9ea2a1..b78eded 100644 --- a/drone/repo/repo_info.go +++ b/drone/repo/repo_info.go @@ -5,6 +5,7 @@ import ( "text/template" "github.com/drone/drone-cli/drone/internal" + "github.com/drone/funcmap" "github.com/urfave/cli" ) @@ -39,7 +40,7 @@ func repoInfo(c *cli.Context) error { return err } - tmpl, err := template.New("_").Parse(c.String("format")) + tmpl, err := template.New("_").Funcs(funcmap.Funcs).Parse(c.String("format")) if err != nil { return err } diff --git a/drone/repo/repo_list.go b/drone/repo/repo_list.go index 3c96643..26b55d7 100644 --- a/drone/repo/repo_list.go +++ b/drone/repo/repo_list.go @@ -5,6 +5,7 @@ import ( "text/template" "github.com/drone/drone-cli/drone/internal" + "github.com/drone/funcmap" "github.com/urfave/cli" ) @@ -37,7 +38,7 @@ func repoList(c *cli.Context) error { return err } - tmpl, err := template.New("_").Parse(c.String("format") + "\n") + tmpl, err := template.New("_").Funcs(funcmap.Funcs).Parse(c.String("format") + "\n") if err != nil { return err } diff --git a/drone/repo/repo_sync.go b/drone/repo/repo_sync.go index 21e69d2..e468c7b 100644 --- a/drone/repo/repo_sync.go +++ b/drone/repo/repo_sync.go @@ -5,6 +5,7 @@ import ( "text/template" "github.com/drone/drone-cli/drone/internal" + "github.com/drone/funcmap" "github.com/urfave/cli" ) @@ -33,7 +34,7 @@ func repoSync(c *cli.Context) error { return err } - tmpl, err := template.New("_").Parse(c.String("format") + "\n") + tmpl, err := template.New("_").Funcs(funcmap.Funcs).Parse(c.String("format") + "\n") if err != nil { return err } diff --git a/drone/secret/secret_info.go b/drone/secret/secret_info.go index 4cc826d..ee0ac82 100644 --- a/drone/secret/secret_info.go +++ b/drone/secret/secret_info.go @@ -4,9 +4,9 @@ import ( "html/template" "os" - "github.com/urfave/cli" - "github.com/drone/drone-cli/drone/internal" + "github.com/drone/funcmap" + "github.com/urfave/cli" ) var secretInfoCmd = cli.Command{ @@ -52,7 +52,7 @@ func secretInfo(c *cli.Context) error { if err != nil { return err } - tmpl, err := template.New("_").Parse(format) + tmpl, err := template.New("_").Funcs(funcmap.Funcs).Parse(format) if err != nil { return err } diff --git a/drone/secret/secret_list.go b/drone/secret/secret_list.go index 4ad7897..0b1c721 100644 --- a/drone/secret/secret_list.go +++ b/drone/secret/secret_list.go @@ -4,9 +4,9 @@ import ( "html/template" "os" - "github.com/urfave/cli" - "github.com/drone/drone-cli/drone/internal" + "github.com/drone/funcmap" + "github.com/urfave/cli" ) var secretListCmd = cli.Command{ @@ -47,7 +47,7 @@ func secretList(c *cli.Context) error { if err != nil { return err } - tmpl, err := template.New("_").Parse(format) + tmpl, err := template.New("_").Funcs(funcmap.Funcs).Parse(format) if err != nil { return err } diff --git a/drone/server/server_create.go b/drone/server/server_create.go index 8a3ab32..b5ec78a 100644 --- a/drone/server/server_create.go +++ b/drone/server/server_create.go @@ -4,9 +4,9 @@ import ( "os" "text/template" - "github.com/urfave/cli" - "github.com/drone/drone-cli/drone/internal" + "github.com/drone/funcmap" + "github.com/urfave/cli" ) var serverCreateCmd = cli.Command{ @@ -33,7 +33,7 @@ func serverCreate(c *cli.Context) error { return err } - tmpl, err := template.New("_").Parse(c.String("format") + "\n") + tmpl, err := template.New("_").Funcs(funcmap.Funcs).Parse(c.String("format") + "\n") if err != nil { return err } diff --git a/drone/server/server_destroy.go b/drone/server/server_destroy.go index a8a229b..ff6fa2a 100644 --- a/drone/server/server_destroy.go +++ b/drone/server/server_destroy.go @@ -5,9 +5,9 @@ import ( "os" "text/template" - "github.com/urfave/cli" - "github.com/drone/drone-cli/drone/internal" + "github.com/drone/funcmap" + "github.com/urfave/cli" ) var serverDestroyCmd = cli.Command{ @@ -49,7 +49,7 @@ func serverDestroy(c *cli.Context) error { return err } - tmpl, err := template.New("_").Parse(c.String("format") + "\n") + tmpl, err := template.New("_").Funcs(funcmap.Funcs).Parse(c.String("format") + "\n") if err != nil { return err } diff --git a/drone/server/server_env.go b/drone/server/server_env.go index be0bf98..252af98 100644 --- a/drone/server/server_env.go +++ b/drone/server/server_env.go @@ -9,10 +9,10 @@ import ( "path" "text/template" - "github.com/urfave/cli" - "github.com/drone/drone-cli/drone/internal" "github.com/drone/drone-go/drone" + "github.com/drone/funcmap" + "github.com/urfave/cli" ) var serverEnvCmd = cli.Command{ @@ -108,7 +108,7 @@ func serverEnv(c *cli.Context) error { }) } -var shellT = template.Must(template.New("_").Parse(` +var shellT = template.Must(template.New("_").Funcs(funcmap.Funcs).Parse(` {{- if eq .Shell "fish" -}} sex -x DOCKER_TLS "1"; set -x DOCKER_TLS_VERIFY ""; diff --git a/drone/server/server_info.go b/drone/server/server_info.go index 612fde0..40fd979 100644 --- a/drone/server/server_info.go +++ b/drone/server/server_info.go @@ -5,9 +5,9 @@ import ( "os" "text/template" - "github.com/urfave/cli" - "github.com/drone/drone-cli/drone/internal" + "github.com/drone/funcmap" + "github.com/urfave/cli" ) var serverInfoCmd = cli.Command{ @@ -40,7 +40,7 @@ func serverInfo(c *cli.Context) error { return err } - tmpl, err := template.New("_").Parse(c.String("format") + "\n") + tmpl, err := template.New("_").Funcs(funcmap.Funcs).Parse(c.String("format") + "\n") if err != nil { return err } diff --git a/drone/server/server_list.go b/drone/server/server_list.go index afe17a0..c66b906 100644 --- a/drone/server/server_list.go +++ b/drone/server/server_list.go @@ -8,10 +8,10 @@ import ( "time" "github.com/docker/go-units" - "github.com/urfave/cli" - "github.com/drone/drone-cli/drone/internal" "github.com/drone/drone-go/drone" + "github.com/drone/funcmap" + "github.com/urfave/cli" ) var serverListCmd = cli.Command{ @@ -68,7 +68,7 @@ func serverList(c *cli.Context) error { return nil } - tmpl, err := template.New("_").Parse(c.String("format") + "\n") + tmpl, err := template.New("_").Funcs(funcmap.Funcs).Parse(c.String("format") + "\n") if err != nil { return err } diff --git a/drone/user/user_info.go b/drone/user/user_info.go index 48e200b..b052a90 100644 --- a/drone/user/user_info.go +++ b/drone/user/user_info.go @@ -5,9 +5,9 @@ import ( "os" "text/template" - "github.com/urfave/cli" - "github.com/drone/drone-cli/drone/internal" + "github.com/drone/funcmap" + "github.com/urfave/cli" ) var userInfoCmd = cli.Command{ @@ -40,7 +40,7 @@ func userInfo(c *cli.Context) error { return err } - tmpl, err := template.New("_").Parse(c.String("format") + "\n") + tmpl, err := template.New("_").Funcs(funcmap.Funcs).Parse(c.String("format") + "\n") if err != nil { return err } diff --git a/drone/user/user_list.go b/drone/user/user_list.go index 803d5ee..8cb5be9 100644 --- a/drone/user/user_list.go +++ b/drone/user/user_list.go @@ -4,9 +4,9 @@ import ( "os" "text/template" - "github.com/urfave/cli" - "github.com/drone/drone-cli/drone/internal" + "github.com/drone/funcmap" + "github.com/urfave/cli" ) var userListCmd = cli.Command{ @@ -34,7 +34,7 @@ func userList(c *cli.Context) error { return err } - tmpl, err := template.New("_").Parse(c.String("format") + "\n") + tmpl, err := template.New("_").Funcs(funcmap.Funcs).Parse(c.String("format") + "\n") if err != nil { return err }