mirror of
https://github.com/containers/podman.git
synced 2025-06-22 09:58:10 +08:00
Merge pull request #10688 from jwhonce/bz/1855983
Scrub podman commands to use report package
This commit is contained in:
@ -3,8 +3,6 @@ package containers
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"text/tabwriter"
|
|
||||||
"text/template"
|
|
||||||
|
|
||||||
"github.com/containers/common/pkg/report"
|
"github.com/containers/common/pkg/report"
|
||||||
"github.com/containers/podman/v3/cmd/podman/common"
|
"github.com/containers/podman/v3/cmd/podman/common"
|
||||||
@ -117,12 +115,16 @@ func mount(_ *cobra.Command, args []string) error {
|
|||||||
mrs = append(mrs, mountReporter{r})
|
mrs = append(mrs, mountReporter{r})
|
||||||
}
|
}
|
||||||
|
|
||||||
format := "{{range . }}{{.ID}}\t{{.Path}}\n{{end}}"
|
format := "{{range . }}{{.ID}}\t{{.Path}}\n{{end -}}"
|
||||||
tmpl, err := template.New("mounts").Parse(format)
|
tmpl, err := report.NewTemplate("mounts").Parse(format)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
w, err := report.NewWriterDefault(os.Stdout)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
w := tabwriter.NewWriter(os.Stdout, 8, 2, 2, ' ', 0)
|
|
||||||
defer w.Flush()
|
defer w.Flush()
|
||||||
return tmpl.Execute(w, mrs)
|
return tmpl.Execute(w, mrs)
|
||||||
}
|
}
|
||||||
|
@ -6,15 +6,12 @@ import (
|
|||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"text/tabwriter"
|
|
||||||
"text/template"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
tm "github.com/buger/goterm"
|
tm "github.com/buger/goterm"
|
||||||
"github.com/containers/common/pkg/completion"
|
"github.com/containers/common/pkg/completion"
|
||||||
"github.com/containers/common/pkg/report"
|
"github.com/containers/common/pkg/report"
|
||||||
"github.com/containers/podman/v3/cmd/podman/common"
|
"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/registry"
|
||||||
"github.com/containers/podman/v3/cmd/podman/utils"
|
"github.com/containers/podman/v3/cmd/podman/utils"
|
||||||
"github.com/containers/podman/v3/cmd/podman/validate"
|
"github.com/containers/podman/v3/cmd/podman/validate"
|
||||||
@ -226,18 +223,20 @@ func ps(cmd *cobra.Command, _ []string) error {
|
|||||||
hdrs, format := createPsOut()
|
hdrs, format := createPsOut()
|
||||||
if cmd.Flags().Changed("format") {
|
if cmd.Flags().Changed("format") {
|
||||||
format = report.NormalizeFormat(listOpts.Format)
|
format = report.NormalizeFormat(listOpts.Format)
|
||||||
format = parse.EnforceRange(format)
|
format = report.EnforceRange(format)
|
||||||
}
|
}
|
||||||
ns := strings.NewReplacer(".Namespaces.", ".")
|
ns := strings.NewReplacer(".Namespaces.", ".")
|
||||||
format = ns.Replace(format)
|
format = ns.Replace(format)
|
||||||
|
|
||||||
tmpl, err := template.New("listContainers").
|
tmpl, err := report.NewTemplate("list").Parse(format)
|
||||||
Funcs(template.FuncMap(report.DefaultFuncs)).
|
if err != nil {
|
||||||
Parse(format)
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
w, err := report.NewWriterDefault(os.Stdout)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
w := tabwriter.NewWriter(os.Stdout, 8, 2, 2, ' ', 0)
|
|
||||||
defer w.Flush()
|
defer w.Flush()
|
||||||
|
|
||||||
headers := func() error { return nil }
|
headers := func() error { return nil }
|
||||||
@ -320,7 +319,7 @@ func createPsOut() ([]map[string]string, string) {
|
|||||||
row += "\t{{.Size}}"
|
row += "\t{{.Size}}"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return hdrs, "{{range .}}" + row + "\n{{end}}"
|
return hdrs, "{{range .}}" + row + "\n{{end -}}"
|
||||||
}
|
}
|
||||||
|
|
||||||
type psReporter struct {
|
type psReporter struct {
|
||||||
|
@ -3,13 +3,10 @@ package containers
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"text/tabwriter"
|
|
||||||
"text/template"
|
|
||||||
|
|
||||||
tm "github.com/buger/goterm"
|
tm "github.com/buger/goterm"
|
||||||
"github.com/containers/common/pkg/report"
|
"github.com/containers/common/pkg/report"
|
||||||
"github.com/containers/podman/v3/cmd/podman/common"
|
"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/registry"
|
||||||
"github.com/containers/podman/v3/cmd/podman/validate"
|
"github.com/containers/podman/v3/cmd/podman/validate"
|
||||||
"github.com/containers/podman/v3/libpod/define"
|
"github.com/containers/podman/v3/libpod/define"
|
||||||
@ -170,13 +167,17 @@ func outputStats(reports []define.ContainerStats) error {
|
|||||||
if len(statsOptions.Format) > 0 {
|
if len(statsOptions.Format) > 0 {
|
||||||
format = report.NormalizeFormat(statsOptions.Format)
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
w := tabwriter.NewWriter(os.Stdout, 8, 2, 2, ' ', 0)
|
|
||||||
defer w.Flush()
|
defer w.Flush()
|
||||||
|
|
||||||
if len(statsOptions.Format) < 1 {
|
if len(statsOptions.Format) < 1 {
|
||||||
|
@ -5,8 +5,8 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"text/tabwriter"
|
|
||||||
|
|
||||||
|
"github.com/containers/common/pkg/report"
|
||||||
"github.com/containers/podman/v3/cmd/podman/common"
|
"github.com/containers/podman/v3/cmd/podman/common"
|
||||||
"github.com/containers/podman/v3/cmd/podman/registry"
|
"github.com/containers/podman/v3/cmd/podman/registry"
|
||||||
"github.com/containers/podman/v3/cmd/podman/validate"
|
"github.com/containers/podman/v3/cmd/podman/validate"
|
||||||
@ -77,7 +77,7 @@ func init() {
|
|||||||
validate.AddLatestFlag(containerTopCommand, &topOptions.Latest)
|
validate.AddLatestFlag(containerTopCommand, &topOptions.Latest)
|
||||||
}
|
}
|
||||||
|
|
||||||
func top(cmd *cobra.Command, args []string) error {
|
func top(_ *cobra.Command, args []string) error {
|
||||||
if topOptions.ListDescriptors {
|
if topOptions.ListDescriptors {
|
||||||
descriptors, err := util.GetContainerPidInformationDescriptors()
|
descriptors, err := util.GetContainerPidInformationDescriptors()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -103,7 +103,11 @@ func top(cmd *cobra.Command, args []string) error {
|
|||||||
return err
|
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 {
|
for _, proc := range topResponse.Value {
|
||||||
if _, err := fmt.Fprintln(w, proc); err != nil {
|
if _, err := fmt.Fprintln(w, proc); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -5,14 +5,11 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"text/tabwriter"
|
|
||||||
"text/template"
|
|
||||||
"time"
|
"time"
|
||||||
"unicode"
|
"unicode"
|
||||||
|
|
||||||
"github.com/containers/common/pkg/report"
|
"github.com/containers/common/pkg/report"
|
||||||
"github.com/containers/podman/v3/cmd/podman/common"
|
"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/registry"
|
||||||
"github.com/containers/podman/v3/pkg/domain/entities"
|
"github.com/containers/podman/v3/pkg/domain/entities"
|
||||||
"github.com/docker/go-units"
|
"github.com/docker/go-units"
|
||||||
@ -125,13 +122,17 @@ func history(cmd *cobra.Command, args []string) error {
|
|||||||
case opts.quiet:
|
case opts.quiet:
|
||||||
row = "{{.ID}}\n"
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
w := tabwriter.NewWriter(os.Stdout, 8, 2, 2, ' ', 0)
|
|
||||||
defer w.Flush()
|
defer w.Flush()
|
||||||
|
|
||||||
if !opts.quiet && !cmd.Flags().Changed("format") {
|
if !opts.quiet && !cmd.Flags().Changed("format") {
|
||||||
|
@ -5,8 +5,6 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"text/tabwriter"
|
|
||||||
"text/template"
|
|
||||||
"time"
|
"time"
|
||||||
"unicode"
|
"unicode"
|
||||||
|
|
||||||
@ -14,7 +12,6 @@ import (
|
|||||||
"github.com/containers/common/pkg/report"
|
"github.com/containers/common/pkg/report"
|
||||||
"github.com/containers/image/v5/docker/reference"
|
"github.com/containers/image/v5/docker/reference"
|
||||||
"github.com/containers/podman/v3/cmd/podman/common"
|
"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/registry"
|
||||||
"github.com/containers/podman/v3/pkg/domain/entities"
|
"github.com/containers/podman/v3/pkg/domain/entities"
|
||||||
"github.com/docker/go-units"
|
"github.com/docker/go-units"
|
||||||
@ -140,7 +137,7 @@ func images(cmd *cobra.Command, args []string) error {
|
|||||||
case listFlag.quiet:
|
case listFlag.quiet:
|
||||||
return writeID(imgs)
|
return writeID(imgs)
|
||||||
default:
|
default:
|
||||||
if cmd.Flags().Changed("format") && !parse.HasTable(listFlag.format) {
|
if cmd.Flags().Changed("format") && !report.HasTable(listFlag.format) {
|
||||||
listFlag.noHeading = true
|
listFlag.noHeading = true
|
||||||
}
|
}
|
||||||
return writeTemplate(imgs)
|
return writeTemplate(imgs)
|
||||||
@ -195,20 +192,23 @@ func writeTemplate(imgs []imageReporter) error {
|
|||||||
"ReadOnly": "R/O",
|
"ReadOnly": "R/O",
|
||||||
})
|
})
|
||||||
|
|
||||||
var row string
|
var format string
|
||||||
if listFlag.format == "" {
|
if listFlag.format == "" {
|
||||||
row = lsFormatFromFlags(listFlag)
|
format = lsFormatFromFlags(listFlag)
|
||||||
} else {
|
} 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 {
|
if err != nil {
|
||||||
return err
|
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()
|
defer w.Flush()
|
||||||
|
|
||||||
if !listFlag.noHeading {
|
if !listFlag.noHeading {
|
||||||
@ -337,7 +337,7 @@ func lsFormatFromFlags(flags listFlagType) string {
|
|||||||
row = append(row, "{{.ReadOnly}}")
|
row = append(row, "{{.ReadOnly}}")
|
||||||
}
|
}
|
||||||
|
|
||||||
return strings.Join(row, "\t") + "\n"
|
return "{{range . }}" + strings.Join(row, "\t") + "\n{{end -}}"
|
||||||
}
|
}
|
||||||
|
|
||||||
type imageReporter struct {
|
type imageReporter struct {
|
||||||
|
@ -3,8 +3,6 @@ package images
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"text/tabwriter"
|
|
||||||
"text/template"
|
|
||||||
|
|
||||||
"github.com/containers/common/pkg/report"
|
"github.com/containers/common/pkg/report"
|
||||||
"github.com/containers/podman/v3/cmd/podman/common"
|
"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})
|
mrs = append(mrs, mountReporter{r})
|
||||||
}
|
}
|
||||||
|
|
||||||
row := "{{range . }}{{.ID}}\t{{.Path}}\n{{end}}"
|
row := "{{range . }}{{.ID}}\t{{.Path}}\n{{end -}}"
|
||||||
tmpl, err := template.New("mounts").Parse(row)
|
tmpl, err := report.NewTemplate("mounts").Parse(row)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
w, err := report.NewWriterDefault(os.Stdout)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
w := tabwriter.NewWriter(os.Stdout, 8, 2, 2, ' ', 0)
|
|
||||||
defer w.Flush()
|
defer w.Flush()
|
||||||
|
|
||||||
return tmpl.Execute(w, mrs)
|
return tmpl.Execute(w, mrs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,14 +3,11 @@ package images
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"text/tabwriter"
|
|
||||||
"text/template"
|
|
||||||
|
|
||||||
"github.com/containers/common/pkg/auth"
|
"github.com/containers/common/pkg/auth"
|
||||||
"github.com/containers/common/pkg/completion"
|
"github.com/containers/common/pkg/completion"
|
||||||
"github.com/containers/common/pkg/report"
|
"github.com/containers/common/pkg/report"
|
||||||
"github.com/containers/image/v5/types"
|
"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/cmd/podman/registry"
|
||||||
"github.com/containers/podman/v3/pkg/domain/entities"
|
"github.com/containers/podman/v3/pkg/domain/entities"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
@ -156,18 +153,22 @@ func imageSearch(cmd *cobra.Command, args []string) error {
|
|||||||
case report.IsJSON(searchOptions.Format):
|
case report.IsJSON(searchOptions.Format):
|
||||||
return printArbitraryJSON(searchReport)
|
return printArbitraryJSON(searchReport)
|
||||||
case cmd.Flags().Changed("format"):
|
case cmd.Flags().Changed("format"):
|
||||||
renderHeaders = parse.HasTable(searchOptions.Format)
|
renderHeaders = report.HasTable(searchOptions.Format)
|
||||||
row = report.NormalizeFormat(searchOptions.Format)
|
row = report.NormalizeFormat(searchOptions.Format)
|
||||||
default:
|
default:
|
||||||
row = "{{.Index}}\t{{.Name}}\t{{.Description}}\t{{.Stars}}\t{{.Official}}\t{{.Automated}}\n"
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
w := tabwriter.NewWriter(os.Stdout, 8, 2, 2, ' ', 0)
|
|
||||||
defer w.Flush()
|
defer w.Flush()
|
||||||
|
|
||||||
if renderHeaders {
|
if renderHeaders {
|
||||||
|
@ -3,9 +3,8 @@ package images
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"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/common"
|
||||||
"github.com/containers/podman/v3/cmd/podman/registry"
|
"github.com/containers/podman/v3/cmd/podman/registry"
|
||||||
"github.com/containers/podman/v3/pkg/domain/entities"
|
"github.com/containers/podman/v3/pkg/domain/entities"
|
||||||
@ -45,16 +44,16 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func showTrust(cmd *cobra.Command, args []string) error {
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if showTrustOptions.Raw {
|
if showTrustOptions.Raw {
|
||||||
fmt.Println(string(report.Raw))
|
fmt.Println(string(trust.Raw))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if showTrustOptions.JSON {
|
if showTrustOptions.JSON {
|
||||||
b, err := json.MarshalIndent(report.Policies, "", " ")
|
b, err := json.MarshalIndent(trust.Policies, "", " ")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -62,14 +61,18 @@ func showTrust(cmd *cobra.Command, args []string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
row := "{{.RepoName}}\t{{.Type}}\t{{.GPGId}}\t{{.SignatureStore}}\n"
|
format := "{{range . }}{{.RepoName}}\t{{.Type}}\t{{.GPGId}}\t{{.SignatureStore}}\n{{end -}}"
|
||||||
format := "{{range . }}" + row + "{{end}}"
|
tmpl, err := report.NewTemplate("list").Parse(format)
|
||||||
tmpl, err := template.New("listContainers").Parse(format)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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
|
return err
|
||||||
}
|
}
|
||||||
if err := w.Flush(); err != nil {
|
if err := w.Flush(); err != nil {
|
||||||
|
@ -7,7 +7,6 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
"text/tabwriter"
|
|
||||||
"text/template"
|
"text/template"
|
||||||
|
|
||||||
"github.com/containers/common/pkg/completion"
|
"github.com/containers/common/pkg/completion"
|
||||||
@ -217,7 +216,7 @@ func (i *inspector) inspect(namesOrIDs []string) error {
|
|||||||
err = printJSON(data)
|
err = printJSON(data)
|
||||||
default:
|
default:
|
||||||
row := inspectNormalize(i.options.Format)
|
row := inspectNormalize(i.options.Format)
|
||||||
row = "{{range . }}" + report.NormalizeFormat(row) + "{{end}}"
|
row = "{{range . }}" + report.NormalizeFormat(row) + "{{end -}}"
|
||||||
err = printTmpl(tmpType, row, data)
|
err = printTmpl(tmpType, row, data)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -250,7 +249,11 @@ func printTmpl(typ, row string, data []interface{}) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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)
|
return t.Execute(w, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,14 +5,11 @@ package machine
|
|||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"sort"
|
"sort"
|
||||||
"text/tabwriter"
|
|
||||||
"text/template"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/containers/common/pkg/completion"
|
"github.com/containers/common/pkg/completion"
|
||||||
"github.com/containers/common/pkg/config"
|
"github.com/containers/common/pkg/config"
|
||||||
"github.com/containers/common/pkg/report"
|
"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/registry"
|
||||||
"github.com/containers/podman/v3/cmd/podman/validate"
|
"github.com/containers/podman/v3/cmd/podman/validate"
|
||||||
"github.com/containers/podman/v3/pkg/machine"
|
"github.com/containers/podman/v3/pkg/machine"
|
||||||
@ -93,16 +90,20 @@ func outputTemplate(cmd *cobra.Command, responses []*machineReporter) error {
|
|||||||
})
|
})
|
||||||
|
|
||||||
row := report.NormalizeFormat(listFlag.format)
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
w := tabwriter.NewWriter(os.Stdout, 12, 2, 2, ' ', 0)
|
|
||||||
defer w.Flush()
|
defer w.Flush()
|
||||||
|
|
||||||
if cmd.Flags().Changed("format") && !parse.HasTable(listFlag.format) {
|
if cmd.Flags().Changed("format") && !report.HasTable(listFlag.format) {
|
||||||
listFlag.noHeading = true
|
listFlag.noHeading = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,8 +4,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"text/tabwriter"
|
|
||||||
"text/template"
|
|
||||||
|
|
||||||
"github.com/containers/common/pkg/completion"
|
"github.com/containers/common/pkg/completion"
|
||||||
"github.com/containers/common/pkg/report"
|
"github.com/containers/common/pkg/report"
|
||||||
@ -133,11 +131,15 @@ func templateOut(responses []*entities.NetworkListReport, cmd *cobra.Command) er
|
|||||||
}
|
}
|
||||||
format = report.EnforceRange(row)
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
w := tabwriter.NewWriter(os.Stdout, 8, 2, 2, ' ', 0)
|
|
||||||
defer w.Flush()
|
defer w.Flush()
|
||||||
|
|
||||||
noHeading, _ := cmd.Flags().GetBool("noheading")
|
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 (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"os"
|
"os"
|
||||||
"text/tabwriter"
|
|
||||||
"text/template"
|
|
||||||
|
|
||||||
"github.com/containers/common/pkg/report"
|
"github.com/containers/common/pkg/report"
|
||||||
"github.com/containers/podman/v3/cmd/podman/common"
|
"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)
|
row := report.NormalizeFormat(inspectOptions.Format)
|
||||||
|
|
||||||
t, err := template.New("pod inspect").Parse(row)
|
t, err := report.NewTemplate("inspect").Parse(row)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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)
|
return t.Execute(w, *responses)
|
||||||
}
|
}
|
||||||
|
@ -6,14 +6,11 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"text/tabwriter"
|
|
||||||
"text/template"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/containers/common/pkg/completion"
|
"github.com/containers/common/pkg/completion"
|
||||||
"github.com/containers/common/pkg/report"
|
"github.com/containers/common/pkg/report"
|
||||||
"github.com/containers/podman/v3/cmd/podman/common"
|
"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/registry"
|
||||||
"github.com/containers/podman/v3/cmd/podman/validate"
|
"github.com/containers/podman/v3/cmd/podman/validate"
|
||||||
"github.com/containers/podman/v3/pkg/domain/entities"
|
"github.com/containers/podman/v3/pkg/domain/entities"
|
||||||
@ -131,20 +128,24 @@ func pods(cmd *cobra.Command, _ []string) error {
|
|||||||
renderHeaders := true
|
renderHeaders := true
|
||||||
row := podPsFormat()
|
row := podPsFormat()
|
||||||
if cmd.Flags().Changed("format") {
|
if cmd.Flags().Changed("format") {
|
||||||
renderHeaders = parse.HasTable(psInput.Format)
|
renderHeaders = report.HasTable(psInput.Format)
|
||||||
row = report.NormalizeFormat(psInput.Format)
|
row = report.NormalizeFormat(psInput.Format)
|
||||||
}
|
}
|
||||||
noHeading, _ := cmd.Flags().GetBool("noheading")
|
noHeading, _ := cmd.Flags().GetBool("noheading")
|
||||||
if noHeading {
|
if noHeading {
|
||||||
renderHeaders = false
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
w := tabwriter.NewWriter(os.Stdout, 8, 2, 2, ' ', 0)
|
|
||||||
defer w.Flush()
|
defer w.Flush()
|
||||||
|
|
||||||
if renderHeaders {
|
if renderHeaders {
|
||||||
|
@ -4,14 +4,11 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"text/tabwriter"
|
|
||||||
"text/template"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/buger/goterm"
|
"github.com/buger/goterm"
|
||||||
"github.com/containers/common/pkg/report"
|
"github.com/containers/common/pkg/report"
|
||||||
"github.com/containers/podman/v3/cmd/podman/common"
|
"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/registry"
|
||||||
"github.com/containers/podman/v3/cmd/podman/validate"
|
"github.com/containers/podman/v3/cmd/podman/validate"
|
||||||
"github.com/containers/podman/v3/pkg/domain/entities"
|
"github.com/containers/podman/v3/pkg/domain/entities"
|
||||||
@ -123,8 +120,12 @@ func printJSONPodStats(stats []*entities.PodStatsReport) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func printPodStatsLines(stats []*entities.PodStatsReport) {
|
func printPodStatsLines(stats []*entities.PodStatsReport) error {
|
||||||
w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
|
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"
|
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")
|
fmt.Fprintf(w, outFormat, "POD", "CID", "NAME", "CPU %", "MEM USAGE/ LIMIT", "MEM %", "NET IO", "BLOCK IO", "PIDS")
|
||||||
if len(stats) == 0 {
|
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)
|
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 {
|
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
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
w := tabwriter.NewWriter(os.Stdout, 0, 0, 3, ' ', 0)
|
|
||||||
defer w.Flush()
|
defer w.Flush()
|
||||||
|
|
||||||
if err := tmpl.Execute(w, headerNames); err != nil {
|
if err := tmpl.Execute(w, headerNames); err != nil {
|
||||||
|
@ -5,8 +5,8 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"text/tabwriter"
|
|
||||||
|
|
||||||
|
"github.com/containers/common/pkg/report"
|
||||||
"github.com/containers/podman/v3/cmd/podman/common"
|
"github.com/containers/podman/v3/cmd/podman/common"
|
||||||
"github.com/containers/podman/v3/cmd/podman/registry"
|
"github.com/containers/podman/v3/cmd/podman/registry"
|
||||||
"github.com/containers/podman/v3/cmd/podman/validate"
|
"github.com/containers/podman/v3/cmd/podman/validate"
|
||||||
@ -82,7 +82,11 @@ func top(_ *cobra.Command, args []string) error {
|
|||||||
return err
|
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 {
|
for _, proc := range topResponse.Value {
|
||||||
if _, err := fmt.Fprintln(w, proc); err != nil {
|
if _, err := fmt.Fprintln(w, proc); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -4,13 +4,10 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"html/template"
|
|
||||||
"os"
|
"os"
|
||||||
"text/tabwriter"
|
|
||||||
|
|
||||||
"github.com/containers/common/pkg/report"
|
"github.com/containers/common/pkg/report"
|
||||||
"github.com/containers/podman/v3/cmd/podman/common"
|
"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/registry"
|
||||||
"github.com/containers/podman/v3/pkg/domain/entities"
|
"github.com/containers/podman/v3/pkg/domain/entities"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
@ -52,13 +49,17 @@ func inspect(cmd *cobra.Command, args []string) error {
|
|||||||
|
|
||||||
if cmd.Flags().Changed("format") {
|
if cmd.Flags().Changed("format") {
|
||||||
row := report.NormalizeFormat(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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
w := tabwriter.NewWriter(os.Stdout, 12, 2, 2, ' ', 0)
|
|
||||||
defer w.Flush()
|
defer w.Flush()
|
||||||
tmpl.Execute(w, inspected)
|
tmpl.Execute(w, inspected)
|
||||||
} else {
|
} else {
|
||||||
|
@ -2,15 +2,12 @@ package secrets
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"html/template"
|
|
||||||
"os"
|
"os"
|
||||||
"text/tabwriter"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/containers/common/pkg/completion"
|
"github.com/containers/common/pkg/completion"
|
||||||
"github.com/containers/common/pkg/report"
|
"github.com/containers/common/pkg/report"
|
||||||
"github.com/containers/podman/v3/cmd/podman/common"
|
"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/registry"
|
||||||
"github.com/containers/podman/v3/cmd/podman/validate"
|
"github.com/containers/podman/v3/cmd/podman/validate"
|
||||||
"github.com/containers/podman/v3/pkg/domain/entities"
|
"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)
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
w := tabwriter.NewWriter(os.Stdout, 12, 2, 2, ' ', 0)
|
|
||||||
defer w.Flush()
|
defer w.Flush()
|
||||||
|
|
||||||
if cmd.Flags().Changed("format") && !parse.HasTable(listFlag.format) {
|
if cmd.Flags().Changed("format") && !report.HasTable(listFlag.format) {
|
||||||
listFlag.noHeading = true
|
listFlag.noHeading = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,11 +2,10 @@ package connection
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"text/tabwriter"
|
|
||||||
"text/template"
|
|
||||||
|
|
||||||
"github.com/containers/common/pkg/completion"
|
"github.com/containers/common/pkg/completion"
|
||||||
"github.com/containers/common/pkg/config"
|
"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/registry"
|
||||||
"github.com/containers/podman/v3/cmd/podman/system"
|
"github.com/containers/podman/v3/cmd/podman/system"
|
||||||
"github.com/containers/podman/v3/cmd/podman/validate"
|
"github.com/containers/podman/v3/cmd/podman/validate"
|
||||||
@ -73,13 +72,16 @@ func list(_ *cobra.Command, _ []string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Allow user to override format
|
// TODO: Allow user to override format
|
||||||
format := "{{range . }}{{.Name}}\t{{.Identity}}\t{{.URI}}\n{{end}}"
|
format := "{{range . }}{{.Name}}\t{{.Identity}}\t{{.URI}}\n{{end -}}"
|
||||||
tmpl, err := template.New("connection").Parse(format)
|
tmpl, err := report.NewTemplate("list").Parse(format)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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()
|
defer w.Flush()
|
||||||
|
|
||||||
_ = tmpl.Execute(w, hdrs)
|
_ = tmpl.Execute(w, hdrs)
|
||||||
|
@ -4,13 +4,10 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"text/tabwriter"
|
|
||||||
"text/template"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/containers/common/pkg/completion"
|
"github.com/containers/common/pkg/completion"
|
||||||
"github.com/containers/common/pkg/report"
|
"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/registry"
|
||||||
"github.com/containers/podman/v3/cmd/podman/validate"
|
"github.com/containers/podman/v3/cmd/podman/validate"
|
||||||
"github.com/containers/podman/v3/pkg/domain/entities"
|
"github.com/containers/podman/v3/pkg/domain/entities"
|
||||||
@ -57,7 +54,10 @@ func df(cmd *cobra.Command, args []string) error {
|
|||||||
return err
|
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 {
|
if dfOptions.Verbose {
|
||||||
return printVerbose(w, cmd, reports)
|
return printVerbose(w, cmd, reports)
|
||||||
@ -65,7 +65,7 @@ func df(cmd *cobra.Command, args []string) error {
|
|||||||
return printSummary(w, cmd, reports)
|
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 (
|
var (
|
||||||
dfSummaries []*dfSummary
|
dfSummaries []*dfSummary
|
||||||
active int
|
active int
|
||||||
@ -143,7 +143,7 @@ func printSummary(w *tabwriter.Writer, cmd *cobra.Command, reports *entities.Sys
|
|||||||
return writeTemplate(w, cmd, hdrs, row, dfSummaries)
|
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()
|
defer w.Flush()
|
||||||
|
|
||||||
fmt.Fprint(w, "Images space usage:\n\n")
|
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)
|
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()
|
defer w.Flush()
|
||||||
|
|
||||||
format = parse.EnforceRange(format)
|
format = report.EnforceRange(format)
|
||||||
tmpl, err := template.New("df").Parse(format)
|
tmpl, err := report.NewTemplate("df").Parse(format)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"text/template"
|
|
||||||
|
|
||||||
"github.com/containers/common/pkg/completion"
|
"github.com/containers/common/pkg/completion"
|
||||||
"github.com/containers/common/pkg/report"
|
"github.com/containers/common/pkg/report"
|
||||||
@ -75,7 +74,7 @@ func eventsCmd(cmd *cobra.Command, _ []string) error {
|
|||||||
errChannel := make(chan error)
|
errChannel := make(chan error)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
tmpl *template.Template
|
tmpl *report.Template
|
||||||
doJSON bool
|
doJSON bool
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -83,7 +82,7 @@ func eventsCmd(cmd *cobra.Command, _ []string) error {
|
|||||||
doJSON = report.IsJSON(eventFormat)
|
doJSON = report.IsJSON(eventFormat)
|
||||||
if !doJSON {
|
if !doJSON {
|
||||||
var err error
|
var err error
|
||||||
tmpl, err = template.New("events").Parse(eventFormat)
|
tmpl, err = report.NewTemplate("events").Parse(eventFormat)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@ package system
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"text/template"
|
|
||||||
|
|
||||||
"github.com/containers/common/pkg/completion"
|
"github.com/containers/common/pkg/completion"
|
||||||
"github.com/containers/common/pkg/report"
|
"github.com/containers/common/pkg/report"
|
||||||
@ -85,7 +84,7 @@ func info(cmd *cobra.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
fmt.Println(string(b))
|
fmt.Println(string(b))
|
||||||
case cmd.Flags().Changed("format"):
|
case cmd.Flags().Changed("format"):
|
||||||
tmpl, err := template.New("info").Parse(inFormat)
|
tmpl, err := report.NewTemplate("info").Parse(inFormat)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -5,8 +5,6 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"text/tabwriter"
|
|
||||||
"text/template"
|
|
||||||
|
|
||||||
"github.com/containers/common/pkg/completion"
|
"github.com/containers/common/pkg/completion"
|
||||||
"github.com/containers/common/pkg/report"
|
"github.com/containers/common/pkg/report"
|
||||||
@ -55,19 +53,22 @@ func version(cmd *cobra.Command, args []string) error {
|
|||||||
return nil
|
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()
|
defer w.Flush()
|
||||||
|
|
||||||
if cmd.Flag("format").Changed {
|
if cmd.Flag("format").Changed {
|
||||||
row := report.NormalizeFormat(versionFormat)
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := tmpl.Execute(w, versions); err != nil {
|
if err := tmpl.Execute(w, versions); err != nil {
|
||||||
// On Failure, assume user is using older version of podman version --format and check client
|
// On Failure, assume user is using older version of podman version --format and check client
|
||||||
row = strings.Replace(row, ".Server.", ".", 1)
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -5,13 +5,10 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"text/tabwriter"
|
|
||||||
"text/template"
|
|
||||||
|
|
||||||
"github.com/containers/common/pkg/completion"
|
"github.com/containers/common/pkg/completion"
|
||||||
"github.com/containers/common/pkg/report"
|
"github.com/containers/common/pkg/report"
|
||||||
"github.com/containers/podman/v3/cmd/podman/common"
|
"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/registry"
|
||||||
"github.com/containers/podman/v3/cmd/podman/validate"
|
"github.com/containers/podman/v3/cmd/podman/validate"
|
||||||
"github.com/containers/podman/v3/libpod/define"
|
"github.com/containers/podman/v3/libpod/define"
|
||||||
@ -104,13 +101,17 @@ func outputTemplate(cmd *cobra.Command, responses []*entities.VolumeListReport)
|
|||||||
if cliOpts.Quiet {
|
if cliOpts.Quiet {
|
||||||
row = "{{.Name}}\n"
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
w := tabwriter.NewWriter(os.Stdout, 12, 2, 2, ' ', 0)
|
|
||||||
defer w.Flush()
|
defer w.Flush()
|
||||||
|
|
||||||
if !(noHeading || cliOpts.Quiet || cmd.Flag("format").Changed) {
|
if !(noHeading || cliOpts.Quiet || cmd.Flag("format").Changed) {
|
||||||
|
@ -89,9 +89,15 @@ class ImageTestCase(APITestCase):
|
|||||||
|
|
||||||
def test_create(self):
|
def test_create(self):
|
||||||
r = requests.post(
|
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)
|
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)
|
self.assertEqual(r.status_code, 200, r.text)
|
||||||
|
|
||||||
def test_search_compat(self):
|
def test_search_compat(self):
|
||||||
|
@ -101,11 +101,11 @@ var _ = Describe("Podman Info", func() {
|
|||||||
u, err := user.Current()
|
u, err := user.Current()
|
||||||
Expect(err).To(BeNil())
|
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")
|
expect := filepath.Join("/tmp", os.Getenv("HOME"), u.Username, u.Uid, "storage")
|
||||||
podmanPath := podmanTest.PodmanTest.PodmanBinary
|
podmanPath := podmanTest.PodmanTest.PodmanBinary
|
||||||
cmd := exec.Command(podmanPath, "info", "--format", "{{.Store.GraphRoot}}")
|
cmd := exec.Command(podmanPath, "info", "--format", "{{.Store.GraphRoot -}}")
|
||||||
out, err := cmd.CombinedOutput()
|
out, err := cmd.CombinedOutput()
|
||||||
fmt.Println(string(out))
|
|
||||||
Expect(err).To(BeNil())
|
Expect(err).To(BeNil())
|
||||||
Expect(string(out)).To(Equal(expect))
|
Expect(string(out)).To(Equal(expect))
|
||||||
})
|
})
|
||||||
|
@ -19,21 +19,22 @@ load helpers
|
|||||||
|
|
||||||
@test "podman images - custom formats" {
|
@test "podman images - custom formats" {
|
||||||
tests="
|
tests="
|
||||||
--format {{.ID}} | [0-9a-f]\\\{12\\\}
|
{{.ID}} | [0-9a-f]\\\{12\\\}
|
||||||
--format {{.ID}} --no-trunc | sha256:[0-9a-f]\\\{64\\\}
|
{{.ID| upper}} | [0-9A-F]\\\{12\\\}
|
||||||
--format {{.Repository}}:{{.Tag}} | $PODMAN_TEST_IMAGE_FQN
|
{{.Repository}}:{{.Tag}} | $PODMAN_TEST_IMAGE_FQN
|
||||||
--format {{.Labels.created_by}} | test/system/build-testimage
|
{{.Labels.created_by}} | test/system/build-testimage
|
||||||
--format {{.Labels.created_at}} | 20[0-9-]\\\+T[0-9:]\\\+Z
|
{{.Labels.created_at}} | 20[0-9-]\\\+T[0-9:]\\\+Z
|
||||||
"
|
"
|
||||||
|
|
||||||
parse_table "$tests" | while read fmt expect; do
|
parse_table "$tests" | while read fmt expect; do
|
||||||
run_podman images $fmt
|
run_podman images --format "$fmt"
|
||||||
is "$output" "$expect\$" "podman images $fmt"
|
is "$output" "$expect\$" "podman images $fmt"
|
||||||
done
|
done
|
||||||
|
|
||||||
|
run_podman images --format "{{.ID}}" --no-trunc
|
||||||
|
is "$output" "sha256:[0-9a-f]\\{64\\}\$" "podman images --no-trunc"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@test "podman images - json" {
|
@test "podman images - json" {
|
||||||
# 'created': podman includes fractional seconds, podman-remote does not
|
# 'created': podman includes fractional seconds, podman-remote does not
|
||||||
tests="
|
tests="
|
||||||
|
Reference in New Issue
Block a user