summaryrefslogtreecommitdiff
path: root/cmd/podman/system/version.go
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2022-09-13 20:26:24 +0200
committerGitHub <noreply@github.com>2022-09-13 20:26:24 +0200
commitad529f31d82796c17c5a3dde5fed20b84d5bd256 (patch)
tree6d6f50a8e9c9d5d9de2b5bb248d3f54b8ee755fe /cmd/podman/system/version.go
parent6e382d9ec2e6eb79a72537544341e496368b6c63 (diff)
parent9d41b95d72ef29870e6c325557c89c2db818a371 (diff)
downloadpodman-ad529f31d82796c17c5a3dde5fed20b84d5bd256.tar.gz
podman-ad529f31d82796c17c5a3dde5fed20b84d5bd256.tar.bz2
podman-ad529f31d82796c17c5a3dde5fed20b84d5bd256.zip
Merge pull request #15673 from Luap99/template
Fix go template parsing with "\n" in it
Diffstat (limited to 'cmd/podman/system/version.go')
-rw-r--r--cmd/podman/system/version.go19
1 files changed, 11 insertions, 8 deletions
diff --git a/cmd/podman/system/version.go b/cmd/podman/system/version.go
index 7202b2c08..33ab0f757 100644
--- a/cmd/podman/system/version.go
+++ b/cmd/podman/system/version.go
@@ -4,7 +4,6 @@ import (
"fmt"
"os"
"strings"
- "text/template"
"github.com/containers/common/pkg/completion"
"github.com/containers/common/pkg/report"
@@ -12,6 +11,7 @@ import (
"github.com/containers/podman/v4/cmd/podman/registry"
"github.com/containers/podman/v4/cmd/podman/validate"
"github.com/containers/podman/v4/pkg/domain/entities"
+ "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
@@ -53,22 +53,25 @@ func version(cmd *cobra.Command, args []string) error {
}
if cmd.Flag("format").Changed {
- // Cannot use report.New() as it enforces {{range .}} for OriginUser templates
- tmpl := template.New(cmd.Name()).Funcs(template.FuncMap(report.DefaultFuncs))
+ rpt := report.New(os.Stdout, cmd.Name())
+ defer rpt.Flush()
- versionFormat = report.NormalizeFormat(versionFormat)
- tmpl, err := tmpl.Parse(versionFormat)
+ // Use OriginUnknown so it does not add an extra range since it
+ // will only be called for a single element and not a slice.
+ rpt, err = rpt.Parse(report.OriginUnknown, versionFormat)
if err != nil {
return err
}
- if err := tmpl.Execute(os.Stdout, versions); err != nil {
+ if err := rpt.Execute(versions); err != nil {
+ // only log at debug since we fall back to the client only template
+ logrus.Debugf("Failed to execute template: %v", err)
// On Failure, assume user is using older version of podman version --format and check client
versionFormat = strings.ReplaceAll(versionFormat, ".Server.", ".")
- tmpl, err := tmpl.Parse(versionFormat)
+ rpt, err := rpt.Parse(report.OriginUnknown, versionFormat)
if err != nil {
return err
}
- if err := tmpl.Execute(os.Stdout, versions.Client); err != nil {
+ if err := rpt.Execute(versions.Client); err != nil {
return err
}
}