1
0
mirror of https://github.com/drone/drone-cli.git synced 2024-11-23 01:11:57 +01:00

Integrate funcmap for all template executions

This commit is contained in:
Thomas Boerger 2019-09-18 22:36:14 +02:00
parent a986f7c87c
commit 449618ad85
No known key found for this signature in database
GPG Key ID: 09745AFF9D63C79B
30 changed files with 76 additions and 78 deletions

@ -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
}

@ -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
}

@ -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
}

@ -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
}

@ -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
}

@ -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
}

@ -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
}

@ -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()
},
}

@ -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
}

@ -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
}

@ -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
}

@ -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
}

@ -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
}

@ -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
}

@ -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
}

@ -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
}

@ -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
}

@ -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
}

@ -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
}

@ -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
}

@ -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
}

@ -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
}

@ -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
}

@ -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
}

@ -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
}

@ -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 "";

@ -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
}

@ -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
}

@ -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
}

@ -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
}