mirror of
https://github.com/containers/podman.git
synced 2025-06-18 15:39:08 +08:00
Scrub podman commands to use report package
Refactor podman commands that have drifted from using c/common report pkg. Report pkg is needed to implement go template functions. Removed obsolete code from podman which exists in c/common. Latest template library added default newlines and method to remove them. Incorporated needed changes in c/common PR below. Depends on https://github.com/containers/common/pull/624 Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1855983 Signed-off-by: Jhon Honce <jhonce@redhat.com>
This commit is contained in:
@ -3,8 +3,6 @@ package containers
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"text/tabwriter"
|
||||
"text/template"
|
||||
|
||||
"github.com/containers/common/pkg/report"
|
||||
"github.com/containers/podman/v3/cmd/podman/common"
|
||||
@ -117,12 +115,16 @@ func mount(_ *cobra.Command, args []string) error {
|
||||
mrs = append(mrs, mountReporter{r})
|
||||
}
|
||||
|
||||
format := "{{range . }}{{.ID}}\t{{.Path}}\n{{end}}"
|
||||
tmpl, err := template.New("mounts").Parse(format)
|
||||
format := "{{range . }}{{.ID}}\t{{.Path}}\n{{end -}}"
|
||||
tmpl, err := report.NewTemplate("mounts").Parse(format)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
w, err := report.NewWriterDefault(os.Stdout)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
w := tabwriter.NewWriter(os.Stdout, 8, 2, 2, ' ', 0)
|
||||
defer w.Flush()
|
||||
return tmpl.Execute(w, mrs)
|
||||
}
|
||||
|
@ -6,15 +6,12 @@ import (
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"text/tabwriter"
|
||||
"text/template"
|
||||
"time"
|
||||
|
||||
tm "github.com/buger/goterm"
|
||||
"github.com/containers/common/pkg/completion"
|
||||
"github.com/containers/common/pkg/report"
|
||||
"github.com/containers/podman/v3/cmd/podman/common"
|
||||
"github.com/containers/podman/v3/cmd/podman/parse"
|
||||
"github.com/containers/podman/v3/cmd/podman/registry"
|
||||
"github.com/containers/podman/v3/cmd/podman/utils"
|
||||
"github.com/containers/podman/v3/cmd/podman/validate"
|
||||
@ -226,18 +223,20 @@ func ps(cmd *cobra.Command, _ []string) error {
|
||||
hdrs, format := createPsOut()
|
||||
if cmd.Flags().Changed("format") {
|
||||
format = report.NormalizeFormat(listOpts.Format)
|
||||
format = parse.EnforceRange(format)
|
||||
format = report.EnforceRange(format)
|
||||
}
|
||||
ns := strings.NewReplacer(".Namespaces.", ".")
|
||||
format = ns.Replace(format)
|
||||
|
||||
tmpl, err := template.New("listContainers").
|
||||
Funcs(template.FuncMap(report.DefaultFuncs)).
|
||||
Parse(format)
|
||||
tmpl, err := report.NewTemplate("list").Parse(format)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
w, err := report.NewWriterDefault(os.Stdout)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
w := tabwriter.NewWriter(os.Stdout, 8, 2, 2, ' ', 0)
|
||||
defer w.Flush()
|
||||
|
||||
headers := func() error { return nil }
|
||||
@ -320,7 +319,7 @@ func createPsOut() ([]map[string]string, string) {
|
||||
row += "\t{{.Size}}"
|
||||
}
|
||||
}
|
||||
return hdrs, "{{range .}}" + row + "\n{{end}}"
|
||||
return hdrs, "{{range .}}" + row + "\n{{end -}}"
|
||||
}
|
||||
|
||||
type psReporter struct {
|
||||
|
@ -3,13 +3,10 @@ package containers
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"text/tabwriter"
|
||||
"text/template"
|
||||
|
||||
tm "github.com/buger/goterm"
|
||||
"github.com/containers/common/pkg/report"
|
||||
"github.com/containers/podman/v3/cmd/podman/common"
|
||||
"github.com/containers/podman/v3/cmd/podman/parse"
|
||||
"github.com/containers/podman/v3/cmd/podman/registry"
|
||||
"github.com/containers/podman/v3/cmd/podman/validate"
|
||||
"github.com/containers/podman/v3/libpod/define"
|
||||
@ -170,13 +167,17 @@ func outputStats(reports []define.ContainerStats) error {
|
||||
if len(statsOptions.Format) > 0 {
|
||||
format = report.NormalizeFormat(statsOptions.Format)
|
||||
}
|
||||
format = parse.EnforceRange(format)
|
||||
format = report.EnforceRange(format)
|
||||
|
||||
tmpl, err := template.New("stats").Parse(format)
|
||||
tmpl, err := report.NewTemplate("stats").Parse(format)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
w, err := report.NewWriterDefault(os.Stdout)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
w := tabwriter.NewWriter(os.Stdout, 8, 2, 2, ' ', 0)
|
||||
defer w.Flush()
|
||||
|
||||
if len(statsOptions.Format) < 1 {
|
||||
|
@ -5,8 +5,8 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
"text/tabwriter"
|
||||
|
||||
"github.com/containers/common/pkg/report"
|
||||
"github.com/containers/podman/v3/cmd/podman/common"
|
||||
"github.com/containers/podman/v3/cmd/podman/registry"
|
||||
"github.com/containers/podman/v3/cmd/podman/validate"
|
||||
@ -77,7 +77,7 @@ func init() {
|
||||
validate.AddLatestFlag(containerTopCommand, &topOptions.Latest)
|
||||
}
|
||||
|
||||
func top(cmd *cobra.Command, args []string) error {
|
||||
func top(_ *cobra.Command, args []string) error {
|
||||
if topOptions.ListDescriptors {
|
||||
descriptors, err := util.GetContainerPidInformationDescriptors()
|
||||
if err != nil {
|
||||
@ -103,7 +103,11 @@ func top(cmd *cobra.Command, args []string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
w := tabwriter.NewWriter(os.Stdout, 5, 1, 3, ' ', 0)
|
||||
w, err := report.NewWriterDefault(os.Stdout)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, proc := range topResponse.Value {
|
||||
if _, err := fmt.Fprintln(w, proc); err != nil {
|
||||
return err
|
||||
|
@ -5,14 +5,11 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
"text/tabwriter"
|
||||
"text/template"
|
||||
"time"
|
||||
"unicode"
|
||||
|
||||
"github.com/containers/common/pkg/report"
|
||||
"github.com/containers/podman/v3/cmd/podman/common"
|
||||
"github.com/containers/podman/v3/cmd/podman/parse"
|
||||
"github.com/containers/podman/v3/cmd/podman/registry"
|
||||
"github.com/containers/podman/v3/pkg/domain/entities"
|
||||
"github.com/docker/go-units"
|
||||
@ -125,13 +122,17 @@ func history(cmd *cobra.Command, args []string) error {
|
||||
case opts.quiet:
|
||||
row = "{{.ID}}\n"
|
||||
}
|
||||
format := parse.EnforceRange(row)
|
||||
format := report.EnforceRange(row)
|
||||
|
||||
tmpl, err := template.New("report").Parse(format)
|
||||
tmpl, err := report.NewTemplate("history").Parse(format)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
w, err := report.NewWriterDefault(os.Stdout)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
w := tabwriter.NewWriter(os.Stdout, 8, 2, 2, ' ', 0)
|
||||
defer w.Flush()
|
||||
|
||||
if !opts.quiet && !cmd.Flags().Changed("format") {
|
||||
|
@ -5,8 +5,6 @@ import (
|
||||
"os"
|
||||
"sort"
|
||||
"strings"
|
||||
"text/tabwriter"
|
||||
"text/template"
|
||||
"time"
|
||||
"unicode"
|
||||
|
||||
@ -14,7 +12,6 @@ import (
|
||||
"github.com/containers/common/pkg/report"
|
||||
"github.com/containers/image/v5/docker/reference"
|
||||
"github.com/containers/podman/v3/cmd/podman/common"
|
||||
"github.com/containers/podman/v3/cmd/podman/parse"
|
||||
"github.com/containers/podman/v3/cmd/podman/registry"
|
||||
"github.com/containers/podman/v3/pkg/domain/entities"
|
||||
"github.com/docker/go-units"
|
||||
@ -140,7 +137,7 @@ func images(cmd *cobra.Command, args []string) error {
|
||||
case listFlag.quiet:
|
||||
return writeID(imgs)
|
||||
default:
|
||||
if cmd.Flags().Changed("format") && !parse.HasTable(listFlag.format) {
|
||||
if cmd.Flags().Changed("format") && !report.HasTable(listFlag.format) {
|
||||
listFlag.noHeading = true
|
||||
}
|
||||
return writeTemplate(imgs)
|
||||
@ -195,20 +192,23 @@ func writeTemplate(imgs []imageReporter) error {
|
||||
"ReadOnly": "R/O",
|
||||
})
|
||||
|
||||
var row string
|
||||
var format string
|
||||
if listFlag.format == "" {
|
||||
row = lsFormatFromFlags(listFlag)
|
||||
format = lsFormatFromFlags(listFlag)
|
||||
} else {
|
||||
row = report.NormalizeFormat(listFlag.format)
|
||||
format = report.NormalizeFormat(listFlag.format)
|
||||
format = report.EnforceRange(format)
|
||||
}
|
||||
format := parse.EnforceRange(row)
|
||||
|
||||
tmpl, err := template.New("list").Parse(format)
|
||||
tmpl, err := report.NewTemplate("list").Parse(format)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
w := tabwriter.NewWriter(os.Stdout, 8, 2, 2, ' ', 0)
|
||||
w, err := report.NewWriterDefault(os.Stdout)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer w.Flush()
|
||||
|
||||
if !listFlag.noHeading {
|
||||
@ -337,7 +337,7 @@ func lsFormatFromFlags(flags listFlagType) string {
|
||||
row = append(row, "{{.ReadOnly}}")
|
||||
}
|
||||
|
||||
return strings.Join(row, "\t") + "\n"
|
||||
return "{{range . }}" + strings.Join(row, "\t") + "\n{{end -}}"
|
||||
}
|
||||
|
||||
type imageReporter struct {
|
||||
|
@ -3,8 +3,6 @@ package images
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"text/tabwriter"
|
||||
"text/template"
|
||||
|
||||
"github.com/containers/common/pkg/report"
|
||||
"github.com/containers/podman/v3/cmd/podman/common"
|
||||
@ -99,13 +97,18 @@ func mount(cmd *cobra.Command, args []string) error {
|
||||
mrs = append(mrs, mountReporter{r})
|
||||
}
|
||||
|
||||
row := "{{range . }}{{.ID}}\t{{.Path}}\n{{end}}"
|
||||
tmpl, err := template.New("mounts").Parse(row)
|
||||
row := "{{range . }}{{.ID}}\t{{.Path}}\n{{end -}}"
|
||||
tmpl, err := report.NewTemplate("mounts").Parse(row)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
w, err := report.NewWriterDefault(os.Stdout)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
w := tabwriter.NewWriter(os.Stdout, 8, 2, 2, ' ', 0)
|
||||
defer w.Flush()
|
||||
|
||||
return tmpl.Execute(w, mrs)
|
||||
}
|
||||
|
||||
|
@ -3,14 +3,11 @@ package images
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"text/tabwriter"
|
||||
"text/template"
|
||||
|
||||
"github.com/containers/common/pkg/auth"
|
||||
"github.com/containers/common/pkg/completion"
|
||||
"github.com/containers/common/pkg/report"
|
||||
"github.com/containers/image/v5/types"
|
||||
"github.com/containers/podman/v3/cmd/podman/parse"
|
||||
"github.com/containers/podman/v3/cmd/podman/registry"
|
||||
"github.com/containers/podman/v3/pkg/domain/entities"
|
||||
"github.com/pkg/errors"
|
||||
@ -156,18 +153,22 @@ func imageSearch(cmd *cobra.Command, args []string) error {
|
||||
case report.IsJSON(searchOptions.Format):
|
||||
return printArbitraryJSON(searchReport)
|
||||
case cmd.Flags().Changed("format"):
|
||||
renderHeaders = parse.HasTable(searchOptions.Format)
|
||||
renderHeaders = report.HasTable(searchOptions.Format)
|
||||
row = report.NormalizeFormat(searchOptions.Format)
|
||||
default:
|
||||
row = "{{.Index}}\t{{.Name}}\t{{.Description}}\t{{.Stars}}\t{{.Official}}\t{{.Automated}}\n"
|
||||
}
|
||||
format := parse.EnforceRange(row)
|
||||
format := report.EnforceRange(row)
|
||||
|
||||
tmpl, err := template.New("search").Parse(format)
|
||||
tmpl, err := report.NewTemplate("search").Parse(format)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
w, err := report.NewWriterDefault(os.Stdout)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
w := tabwriter.NewWriter(os.Stdout, 8, 2, 2, ' ', 0)
|
||||
defer w.Flush()
|
||||
|
||||
if renderHeaders {
|
||||
|
@ -3,9 +3,8 @@ package images
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"text/tabwriter"
|
||||
"text/template"
|
||||
|
||||
"github.com/containers/common/pkg/report"
|
||||
"github.com/containers/podman/v3/cmd/podman/common"
|
||||
"github.com/containers/podman/v3/cmd/podman/registry"
|
||||
"github.com/containers/podman/v3/pkg/domain/entities"
|
||||
@ -45,16 +44,16 @@ func init() {
|
||||
}
|
||||
|
||||
func showTrust(cmd *cobra.Command, args []string) error {
|
||||
report, err := registry.ImageEngine().ShowTrust(registry.Context(), args, showTrustOptions)
|
||||
trust, err := registry.ImageEngine().ShowTrust(registry.Context(), args, showTrustOptions)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if showTrustOptions.Raw {
|
||||
fmt.Println(string(report.Raw))
|
||||
fmt.Println(string(trust.Raw))
|
||||
return nil
|
||||
}
|
||||
if showTrustOptions.JSON {
|
||||
b, err := json.MarshalIndent(report.Policies, "", " ")
|
||||
b, err := json.MarshalIndent(trust.Policies, "", " ")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -62,14 +61,18 @@ func showTrust(cmd *cobra.Command, args []string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
row := "{{.RepoName}}\t{{.Type}}\t{{.GPGId}}\t{{.SignatureStore}}\n"
|
||||
format := "{{range . }}" + row + "{{end}}"
|
||||
tmpl, err := template.New("listContainers").Parse(format)
|
||||
format := "{{range . }}{{.RepoName}}\t{{.Type}}\t{{.GPGId}}\t{{.SignatureStore}}\n{{end -}}"
|
||||
tmpl, err := report.NewTemplate("list").Parse(format)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
w := tabwriter.NewWriter(os.Stdout, 8, 2, 2, ' ', 0)
|
||||
if err := tmpl.Execute(w, report.Policies); err != nil {
|
||||
|
||||
w, err := report.NewWriterDefault(os.Stdout)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := tmpl.Execute(w, trust.Policies); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := w.Flush(); err != nil {
|
||||
|
@ -7,7 +7,6 @@ import (
|
||||
"os"
|
||||
"regexp"
|
||||
"strings"
|
||||
"text/tabwriter"
|
||||
"text/template"
|
||||
|
||||
"github.com/containers/common/pkg/completion"
|
||||
@ -217,7 +216,7 @@ func (i *inspector) inspect(namesOrIDs []string) error {
|
||||
err = printJSON(data)
|
||||
default:
|
||||
row := inspectNormalize(i.options.Format)
|
||||
row = "{{range . }}" + report.NormalizeFormat(row) + "{{end}}"
|
||||
row = "{{range . }}" + report.NormalizeFormat(row) + "{{end -}}"
|
||||
err = printTmpl(tmpType, row, data)
|
||||
}
|
||||
if err != nil {
|
||||
@ -250,7 +249,11 @@ func printTmpl(typ, row string, data []interface{}) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
w := tabwriter.NewWriter(os.Stdout, 8, 2, 2, ' ', 0)
|
||||
|
||||
w, err := report.NewWriterDefault(os.Stdout)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return t.Execute(w, data)
|
||||
}
|
||||
|
||||
|
@ -5,14 +5,11 @@ package machine
|
||||
import (
|
||||
"os"
|
||||
"sort"
|
||||
"text/tabwriter"
|
||||
"text/template"
|
||||
"time"
|
||||
|
||||
"github.com/containers/common/pkg/completion"
|
||||
"github.com/containers/common/pkg/config"
|
||||
"github.com/containers/common/pkg/report"
|
||||
"github.com/containers/podman/v3/cmd/podman/parse"
|
||||
"github.com/containers/podman/v3/cmd/podman/registry"
|
||||
"github.com/containers/podman/v3/cmd/podman/validate"
|
||||
"github.com/containers/podman/v3/pkg/machine"
|
||||
@ -93,16 +90,20 @@ func outputTemplate(cmd *cobra.Command, responses []*machineReporter) error {
|
||||
})
|
||||
|
||||
row := report.NormalizeFormat(listFlag.format)
|
||||
format := parse.EnforceRange(row)
|
||||
format := report.EnforceRange(row)
|
||||
|
||||
tmpl, err := template.New("list machines").Parse(format)
|
||||
tmpl, err := report.NewTemplate("list").Parse(format)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
w, err := report.NewWriterDefault(os.Stdout)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
w := tabwriter.NewWriter(os.Stdout, 12, 2, 2, ' ', 0)
|
||||
defer w.Flush()
|
||||
|
||||
if cmd.Flags().Changed("format") && !parse.HasTable(listFlag.format) {
|
||||
if cmd.Flags().Changed("format") && !report.HasTable(listFlag.format) {
|
||||
listFlag.noHeading = true
|
||||
}
|
||||
|
||||
|
@ -4,8 +4,6 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
"text/tabwriter"
|
||||
"text/template"
|
||||
|
||||
"github.com/containers/common/pkg/completion"
|
||||
"github.com/containers/common/pkg/report"
|
||||
@ -133,11 +131,15 @@ func templateOut(responses []*entities.NetworkListReport, cmd *cobra.Command) er
|
||||
}
|
||||
format = report.EnforceRange(row)
|
||||
|
||||
tmpl, err := template.New("listNetworks").Parse(format)
|
||||
tmpl, err := report.NewTemplate("list").Parse(format)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
w, err := report.NewWriterDefault(os.Stdout)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
w := tabwriter.NewWriter(os.Stdout, 8, 2, 2, ' ', 0)
|
||||
defer w.Flush()
|
||||
|
||||
noHeading, _ := cmd.Flags().GetBool("noheading")
|
||||
|
@ -1,22 +0,0 @@
|
||||
package parse
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var rangeRegex = regexp.MustCompile(`{{\s*range\s*\.\s*}}.*{{\s*end\s*}}`)
|
||||
|
||||
// TODO move to github.com/containers/common/pkg/report
|
||||
// EnforceRange ensures that the format string contains a range
|
||||
func EnforceRange(format string) string {
|
||||
if !rangeRegex.MatchString(format) {
|
||||
return "{{range .}}" + format + "{{end}}"
|
||||
}
|
||||
return format
|
||||
}
|
||||
|
||||
// EnforceRange ensures that the format string contains a range
|
||||
func HasTable(format string) bool {
|
||||
return strings.HasPrefix(format, "table ")
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
package parse
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestEnforceRange(t *testing.T) {
|
||||
tests := []struct {
|
||||
input string
|
||||
expected string
|
||||
}{
|
||||
{"{{range .}}{{.ID}}{{end}}", "{{range .}}{{.ID}}{{end}}"},
|
||||
{"{{.ID}}", "{{range .}}{{.ID}}{{end}}"},
|
||||
{"{{ range . }}{{ .ID }}{{ end }}", "{{ range . }}{{ .ID }}{{ end }}"},
|
||||
// EnforceRange does not verify syntax or semantics, that will happen later
|
||||
{"{{range .}}{{.ID}}", "{{range .}}{{range .}}{{.ID}}{{end}}"},
|
||||
{".ID", "{{range .}}.ID{{end}}"},
|
||||
}
|
||||
|
||||
for _, tc := range tests {
|
||||
tc := tc
|
||||
label := "TestEnforceRange_" + tc.input
|
||||
t.Run(label, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
assert.Equal(t, tc.expected, EnforceRange(tc.input))
|
||||
})
|
||||
}
|
||||
}
|
@ -3,8 +3,6 @@ package pods
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"text/tabwriter"
|
||||
"text/template"
|
||||
|
||||
"github.com/containers/common/pkg/report"
|
||||
"github.com/containers/podman/v3/cmd/podman/common"
|
||||
@ -73,11 +71,14 @@ func inspect(cmd *cobra.Command, args []string) error {
|
||||
|
||||
row := report.NormalizeFormat(inspectOptions.Format)
|
||||
|
||||
t, err := template.New("pod inspect").Parse(row)
|
||||
t, err := report.NewTemplate("inspect").Parse(row)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
w := tabwriter.NewWriter(os.Stdout, 8, 2, 2, ' ', 0)
|
||||
w, err := report.NewWriterDefault(os.Stdout)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return t.Execute(w, *responses)
|
||||
}
|
||||
|
@ -6,14 +6,11 @@ import (
|
||||
"os"
|
||||
"sort"
|
||||
"strings"
|
||||
"text/tabwriter"
|
||||
"text/template"
|
||||
"time"
|
||||
|
||||
"github.com/containers/common/pkg/completion"
|
||||
"github.com/containers/common/pkg/report"
|
||||
"github.com/containers/podman/v3/cmd/podman/common"
|
||||
"github.com/containers/podman/v3/cmd/podman/parse"
|
||||
"github.com/containers/podman/v3/cmd/podman/registry"
|
||||
"github.com/containers/podman/v3/cmd/podman/validate"
|
||||
"github.com/containers/podman/v3/pkg/domain/entities"
|
||||
@ -131,20 +128,24 @@ func pods(cmd *cobra.Command, _ []string) error {
|
||||
renderHeaders := true
|
||||
row := podPsFormat()
|
||||
if cmd.Flags().Changed("format") {
|
||||
renderHeaders = parse.HasTable(psInput.Format)
|
||||
renderHeaders = report.HasTable(psInput.Format)
|
||||
row = report.NormalizeFormat(psInput.Format)
|
||||
}
|
||||
noHeading, _ := cmd.Flags().GetBool("noheading")
|
||||
if noHeading {
|
||||
renderHeaders = false
|
||||
}
|
||||
format := parse.EnforceRange(row)
|
||||
format := report.EnforceRange(row)
|
||||
|
||||
tmpl, err := template.New("listPods").Parse(format)
|
||||
tmpl, err := report.NewTemplate("list").Parse(format)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
w, err := report.NewWriterDefault(os.Stdout)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
w := tabwriter.NewWriter(os.Stdout, 8, 2, 2, ' ', 0)
|
||||
defer w.Flush()
|
||||
|
||||
if renderHeaders {
|
||||
|
@ -4,14 +4,11 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"text/tabwriter"
|
||||
"text/template"
|
||||
"time"
|
||||
|
||||
"github.com/buger/goterm"
|
||||
"github.com/containers/common/pkg/report"
|
||||
"github.com/containers/podman/v3/cmd/podman/common"
|
||||
"github.com/containers/podman/v3/cmd/podman/parse"
|
||||
"github.com/containers/podman/v3/cmd/podman/registry"
|
||||
"github.com/containers/podman/v3/cmd/podman/validate"
|
||||
"github.com/containers/podman/v3/pkg/domain/entities"
|
||||
@ -123,8 +120,12 @@ func printJSONPodStats(stats []*entities.PodStatsReport) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func printPodStatsLines(stats []*entities.PodStatsReport) {
|
||||
w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
|
||||
func printPodStatsLines(stats []*entities.PodStatsReport) error {
|
||||
w, err := report.NewWriterDefault(os.Stdout)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
outFormat := "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n"
|
||||
fmt.Fprintf(w, outFormat, "POD", "CID", "NAME", "CPU %", "MEM USAGE/ LIMIT", "MEM %", "NET IO", "BLOCK IO", "PIDS")
|
||||
if len(stats) == 0 {
|
||||
@ -134,7 +135,7 @@ func printPodStatsLines(stats []*entities.PodStatsReport) {
|
||||
fmt.Fprintf(w, outFormat, i.Pod, i.CID, i.Name, i.CPU, i.MemUsage, i.Mem, i.NetIO, i.BlockIO, i.PIDS)
|
||||
}
|
||||
}
|
||||
w.Flush()
|
||||
return w.Flush()
|
||||
}
|
||||
|
||||
func printFormattedPodStatsLines(headerNames []map[string]string, row string, stats []*entities.PodStatsReport) error {
|
||||
@ -142,13 +143,17 @@ func printFormattedPodStatsLines(headerNames []map[string]string, row string, st
|
||||
return nil
|
||||
}
|
||||
|
||||
row = parse.EnforceRange(row)
|
||||
row = report.EnforceRange(row)
|
||||
|
||||
tmpl, err := template.New("pod stats").Parse(row)
|
||||
tmpl, err := report.NewTemplate("stats").Parse(row)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
w, err := report.NewWriterDefault(os.Stdout)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
w := tabwriter.NewWriter(os.Stdout, 0, 0, 3, ' ', 0)
|
||||
defer w.Flush()
|
||||
|
||||
if err := tmpl.Execute(w, headerNames); err != nil {
|
||||
|
@ -5,8 +5,8 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
"text/tabwriter"
|
||||
|
||||
"github.com/containers/common/pkg/report"
|
||||
"github.com/containers/podman/v3/cmd/podman/common"
|
||||
"github.com/containers/podman/v3/cmd/podman/registry"
|
||||
"github.com/containers/podman/v3/cmd/podman/validate"
|
||||
@ -82,7 +82,11 @@ func top(_ *cobra.Command, args []string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
w := tabwriter.NewWriter(os.Stdout, 5, 1, 3, ' ', 0)
|
||||
w, err := report.NewWriterDefault(os.Stdout)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, proc := range topResponse.Value {
|
||||
if _, err := fmt.Fprintln(w, proc); err != nil {
|
||||
return err
|
||||
|
@ -4,13 +4,10 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"os"
|
||||
"text/tabwriter"
|
||||
|
||||
"github.com/containers/common/pkg/report"
|
||||
"github.com/containers/podman/v3/cmd/podman/common"
|
||||
"github.com/containers/podman/v3/cmd/podman/parse"
|
||||
"github.com/containers/podman/v3/cmd/podman/registry"
|
||||
"github.com/containers/podman/v3/pkg/domain/entities"
|
||||
"github.com/pkg/errors"
|
||||
@ -52,13 +49,17 @@ func inspect(cmd *cobra.Command, args []string) error {
|
||||
|
||||
if cmd.Flags().Changed("format") {
|
||||
row := report.NormalizeFormat(format)
|
||||
formatted := parse.EnforceRange(row)
|
||||
formatted := report.EnforceRange(row)
|
||||
|
||||
tmpl, err := template.New("inspect secret").Parse(formatted)
|
||||
tmpl, err := report.NewTemplate("inspect").Parse(formatted)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
w, err := report.NewWriterDefault(os.Stdout)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
w := tabwriter.NewWriter(os.Stdout, 12, 2, 2, ' ', 0)
|
||||
defer w.Flush()
|
||||
tmpl.Execute(w, inspected)
|
||||
} else {
|
||||
|
@ -2,15 +2,12 @@ package secrets
|
||||
|
||||
import (
|
||||
"context"
|
||||
"html/template"
|
||||
"os"
|
||||
"text/tabwriter"
|
||||
"time"
|
||||
|
||||
"github.com/containers/common/pkg/completion"
|
||||
"github.com/containers/common/pkg/report"
|
||||
"github.com/containers/podman/v3/cmd/podman/common"
|
||||
"github.com/containers/podman/v3/cmd/podman/parse"
|
||||
"github.com/containers/podman/v3/cmd/podman/registry"
|
||||
"github.com/containers/podman/v3/cmd/podman/validate"
|
||||
"github.com/containers/podman/v3/pkg/domain/entities"
|
||||
@ -75,16 +72,20 @@ func outputTemplate(cmd *cobra.Command, responses []*entities.SecretListReport)
|
||||
})
|
||||
|
||||
row := report.NormalizeFormat(listFlag.format)
|
||||
format := parse.EnforceRange(row)
|
||||
format := report.EnforceRange(row)
|
||||
|
||||
tmpl, err := template.New("list secret").Parse(format)
|
||||
tmpl, err := report.NewTemplate("list").Parse(format)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
w, err := report.NewWriterDefault(os.Stdout)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
w := tabwriter.NewWriter(os.Stdout, 12, 2, 2, ' ', 0)
|
||||
defer w.Flush()
|
||||
|
||||
if cmd.Flags().Changed("format") && !parse.HasTable(listFlag.format) {
|
||||
if cmd.Flags().Changed("format") && !report.HasTable(listFlag.format) {
|
||||
listFlag.noHeading = true
|
||||
}
|
||||
|
||||
|
@ -2,11 +2,10 @@ package connection
|
||||
|
||||
import (
|
||||
"os"
|
||||
"text/tabwriter"
|
||||
"text/template"
|
||||
|
||||
"github.com/containers/common/pkg/completion"
|
||||
"github.com/containers/common/pkg/config"
|
||||
"github.com/containers/common/pkg/report"
|
||||
"github.com/containers/podman/v3/cmd/podman/registry"
|
||||
"github.com/containers/podman/v3/cmd/podman/system"
|
||||
"github.com/containers/podman/v3/cmd/podman/validate"
|
||||
@ -73,13 +72,16 @@ func list(_ *cobra.Command, _ []string) error {
|
||||
}
|
||||
|
||||
// TODO: Allow user to override format
|
||||
format := "{{range . }}{{.Name}}\t{{.Identity}}\t{{.URI}}\n{{end}}"
|
||||
tmpl, err := template.New("connection").Parse(format)
|
||||
format := "{{range . }}{{.Name}}\t{{.Identity}}\t{{.URI}}\n{{end -}}"
|
||||
tmpl, err := report.NewTemplate("list").Parse(format)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
w := tabwriter.NewWriter(os.Stdout, 8, 2, 2, ' ', 0)
|
||||
w, err := report.NewWriterDefault(os.Stdout)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer w.Flush()
|
||||
|
||||
_ = tmpl.Execute(w, hdrs)
|
||||
|
@ -4,13 +4,10 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
"text/tabwriter"
|
||||
"text/template"
|
||||
"time"
|
||||
|
||||
"github.com/containers/common/pkg/completion"
|
||||
"github.com/containers/common/pkg/report"
|
||||
"github.com/containers/podman/v3/cmd/podman/parse"
|
||||
"github.com/containers/podman/v3/cmd/podman/registry"
|
||||
"github.com/containers/podman/v3/cmd/podman/validate"
|
||||
"github.com/containers/podman/v3/pkg/domain/entities"
|
||||
@ -57,7 +54,10 @@ func df(cmd *cobra.Command, args []string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
w := tabwriter.NewWriter(os.Stdout, 8, 2, 2, ' ', 0)
|
||||
w, err := report.NewWriterDefault(os.Stdout)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if dfOptions.Verbose {
|
||||
return printVerbose(w, cmd, reports)
|
||||
@ -65,7 +65,7 @@ func df(cmd *cobra.Command, args []string) error {
|
||||
return printSummary(w, cmd, reports)
|
||||
}
|
||||
|
||||
func printSummary(w *tabwriter.Writer, cmd *cobra.Command, reports *entities.SystemDfReport) error {
|
||||
func printSummary(w *report.Writer, cmd *cobra.Command, reports *entities.SystemDfReport) error {
|
||||
var (
|
||||
dfSummaries []*dfSummary
|
||||
active int
|
||||
@ -143,7 +143,7 @@ func printSummary(w *tabwriter.Writer, cmd *cobra.Command, reports *entities.Sys
|
||||
return writeTemplate(w, cmd, hdrs, row, dfSummaries)
|
||||
}
|
||||
|
||||
func printVerbose(w *tabwriter.Writer, cmd *cobra.Command, reports *entities.SystemDfReport) error {
|
||||
func printVerbose(w *report.Writer, cmd *cobra.Command, reports *entities.SystemDfReport) error {
|
||||
defer w.Flush()
|
||||
|
||||
fmt.Fprint(w, "Images space usage:\n\n")
|
||||
@ -191,11 +191,11 @@ func printVerbose(w *tabwriter.Writer, cmd *cobra.Command, reports *entities.Sys
|
||||
return writeTemplate(w, cmd, hdrs, volumeRow, dfVolumes)
|
||||
}
|
||||
|
||||
func writeTemplate(w *tabwriter.Writer, cmd *cobra.Command, hdrs []map[string]string, format string, output interface{}) error {
|
||||
func writeTemplate(w *report.Writer, cmd *cobra.Command, hdrs []map[string]string, format string, output interface{}) error {
|
||||
defer w.Flush()
|
||||
|
||||
format = parse.EnforceRange(format)
|
||||
tmpl, err := template.New("df").Parse(format)
|
||||
format = report.EnforceRange(format)
|
||||
tmpl, err := report.NewTemplate("df").Parse(format)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"text/template"
|
||||
|
||||
"github.com/containers/common/pkg/completion"
|
||||
"github.com/containers/common/pkg/report"
|
||||
@ -75,7 +74,7 @@ func eventsCmd(cmd *cobra.Command, _ []string) error {
|
||||
errChannel := make(chan error)
|
||||
|
||||
var (
|
||||
tmpl *template.Template
|
||||
tmpl *report.Template
|
||||
doJSON bool
|
||||
)
|
||||
|
||||
@ -83,7 +82,7 @@ func eventsCmd(cmd *cobra.Command, _ []string) error {
|
||||
doJSON = report.IsJSON(eventFormat)
|
||||
if !doJSON {
|
||||
var err error
|
||||
tmpl, err = template.New("events").Parse(eventFormat)
|
||||
tmpl, err = report.NewTemplate("events").Parse(eventFormat)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ package system
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"text/template"
|
||||
|
||||
"github.com/containers/common/pkg/completion"
|
||||
"github.com/containers/common/pkg/report"
|
||||
@ -85,7 +84,7 @@ func info(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
fmt.Println(string(b))
|
||||
case cmd.Flags().Changed("format"):
|
||||
tmpl, err := template.New("info").Parse(inFormat)
|
||||
tmpl, err := report.NewTemplate("info").Parse(inFormat)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -5,8 +5,6 @@ import (
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
"text/tabwriter"
|
||||
"text/template"
|
||||
|
||||
"github.com/containers/common/pkg/completion"
|
||||
"github.com/containers/common/pkg/report"
|
||||
@ -55,19 +53,22 @@ func version(cmd *cobra.Command, args []string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
|
||||
w, err := report.NewWriterDefault(os.Stdout)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer w.Flush()
|
||||
|
||||
if cmd.Flag("format").Changed {
|
||||
row := report.NormalizeFormat(versionFormat)
|
||||
tmpl, err := template.New("version 2.0.0").Parse(row)
|
||||
tmpl, err := report.NewTemplate("version 2.0.0").Parse(row)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := tmpl.Execute(w, versions); err != nil {
|
||||
// On Failure, assume user is using older version of podman version --format and check client
|
||||
row = strings.Replace(row, ".Server.", ".", 1)
|
||||
tmpl, err := template.New("version 1.0.0").Parse(row)
|
||||
tmpl, err := report.NewTemplate("version 1.0.0").Parse(row)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -5,13 +5,10 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
"text/tabwriter"
|
||||
"text/template"
|
||||
|
||||
"github.com/containers/common/pkg/completion"
|
||||
"github.com/containers/common/pkg/report"
|
||||
"github.com/containers/podman/v3/cmd/podman/common"
|
||||
"github.com/containers/podman/v3/cmd/podman/parse"
|
||||
"github.com/containers/podman/v3/cmd/podman/registry"
|
||||
"github.com/containers/podman/v3/cmd/podman/validate"
|
||||
"github.com/containers/podman/v3/libpod/define"
|
||||
@ -104,13 +101,17 @@ func outputTemplate(cmd *cobra.Command, responses []*entities.VolumeListReport)
|
||||
if cliOpts.Quiet {
|
||||
row = "{{.Name}}\n"
|
||||
}
|
||||
format := parse.EnforceRange(row)
|
||||
format := report.EnforceRange(row)
|
||||
|
||||
tmpl, err := template.New("list volume").Parse(format)
|
||||
tmpl, err := report.NewTemplate("list").Parse(format)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
w, err := report.NewWriterDefault(os.Stdout)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
w := tabwriter.NewWriter(os.Stdout, 12, 2, 2, ' ', 0)
|
||||
defer w.Flush()
|
||||
|
||||
if !(noHeading || cliOpts.Quiet || cmd.Flag("format").Changed) {
|
||||
|
@ -89,9 +89,15 @@ class ImageTestCase(APITestCase):
|
||||
|
||||
def test_create(self):
|
||||
r = requests.post(
|
||||
self.podman_url + "/v1.40/images/create?fromImage=alpine&platform=linux/amd64/v8", timeout=15)
|
||||
self.podman_url + "/v1.40/images/create?fromImage=alpine&platform=linux/amd64/v8",
|
||||
timeout=15,
|
||||
)
|
||||
self.assertEqual(r.status_code, 200, r.text)
|
||||
r = requests.post(self.podman_url + "/v1.40/images/create?fromSrc=-&repo=fedora&message=testing123&platform=linux/amd64", timeout=15)
|
||||
r = requests.post(
|
||||
self.podman_url
|
||||
+ "/v1.40/images/create?fromSrc=-&repo=fedora&message=testing123&platform=linux/amd64",
|
||||
timeout=15,
|
||||
)
|
||||
self.assertEqual(r.status_code, 200, r.text)
|
||||
|
||||
def test_search_compat(self):
|
||||
|
@ -101,11 +101,11 @@ var _ = Describe("Podman Info", func() {
|
||||
u, err := user.Current()
|
||||
Expect(err).To(BeNil())
|
||||
|
||||
// Cannot use podmanTest.Podman() and test for storage path
|
||||
expect := filepath.Join("/tmp", os.Getenv("HOME"), u.Username, u.Uid, "storage")
|
||||
podmanPath := podmanTest.PodmanTest.PodmanBinary
|
||||
cmd := exec.Command(podmanPath, "info", "--format", "{{.Store.GraphRoot}}")
|
||||
cmd := exec.Command(podmanPath, "info", "--format", "{{.Store.GraphRoot -}}")
|
||||
out, err := cmd.CombinedOutput()
|
||||
fmt.Println(string(out))
|
||||
Expect(err).To(BeNil())
|
||||
Expect(string(out)).To(Equal(expect))
|
||||
})
|
||||
|
@ -19,21 +19,22 @@ load helpers
|
||||
|
||||
@test "podman images - custom formats" {
|
||||
tests="
|
||||
--format {{.ID}} | [0-9a-f]\\\{12\\\}
|
||||
--format {{.ID}} --no-trunc | sha256:[0-9a-f]\\\{64\\\}
|
||||
--format {{.Repository}}:{{.Tag}} | $PODMAN_TEST_IMAGE_FQN
|
||||
--format {{.Labels.created_by}} | test/system/build-testimage
|
||||
--format {{.Labels.created_at}} | 20[0-9-]\\\+T[0-9:]\\\+Z
|
||||
{{.ID}} | [0-9a-f]\\\{12\\\}
|
||||
{{.ID| upper}} | [0-9A-F]\\\{12\\\}
|
||||
{{.Repository}}:{{.Tag}} | $PODMAN_TEST_IMAGE_FQN
|
||||
{{.Labels.created_by}} | test/system/build-testimage
|
||||
{{.Labels.created_at}} | 20[0-9-]\\\+T[0-9:]\\\+Z
|
||||
"
|
||||
|
||||
parse_table "$tests" | while read fmt expect; do
|
||||
run_podman images $fmt
|
||||
run_podman images --format "$fmt"
|
||||
is "$output" "$expect\$" "podman images $fmt"
|
||||
done
|
||||
|
||||
run_podman images --format "{{.ID}}" --no-trunc
|
||||
is "$output" "sha256:[0-9a-f]\\{64\\}\$" "podman images --no-trunc"
|
||||
}
|
||||
|
||||
|
||||
@test "podman images - json" {
|
||||
# 'created': podman includes fractional seconds, podman-remote does not
|
||||
tests="
|
||||
|
Reference in New Issue
Block a user