Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions cmd/nerdctl/apparmor_ls_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"text/template"

"github.com/containerd/nerdctl/pkg/apparmorutil"
"github.com/containerd/nerdctl/pkg/formatter"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -70,7 +71,7 @@ func apparmorLsAction(cmd *cobra.Command, args []string) error {
return errors.New("format and quiet must not be specified together")
}
var err error
tmpl, err = parseTemplate(format)
tmpl, err = formatter.ParseTemplate(format)
if err != nil {
return err
}
Expand All @@ -96,7 +97,7 @@ func apparmorLsAction(cmd *cobra.Command, args []string) error {
fmt.Fprintf(w, "%s\t%s\n", f.Name, f.Mode)
}
}
if f, ok := w.(Flusher); ok {
if f, ok := w.(formatter.Flusher); ok {
return f.Flush()
}
return nil
Expand Down
8 changes: 6 additions & 2 deletions cmd/nerdctl/container_inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"time"

"github.com/containerd/nerdctl/pkg/containerinspector"
"github.com/containerd/nerdctl/pkg/formatter"
"github.com/containerd/nerdctl/pkg/idutil/containerwalker"
"github.com/containerd/nerdctl/pkg/inspecttypes/dockercompat"

Expand Down Expand Up @@ -81,8 +82,11 @@ func containerInspectAction(cmd *cobra.Command, args []string) error {
if len(errs) > 0 {
return fmt.Errorf("%d errors: %v", len(errs), errs)
}

return formatSlice(cmd, f.entries)
format, err := cmd.Flags().GetString("format")
if err != nil {
return err
}
return formatter.FormatSlice(format, cmd.OutOrStdout(), f.entries)
}

type containerInspector struct {
Expand Down
3 changes: 2 additions & 1 deletion cmd/nerdctl/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (

"github.com/containerd/containerd/events"
"github.com/containerd/containerd/log"
"github.com/containerd/nerdctl/pkg/formatter"
"github.com/containerd/typeurl"

"github.com/spf13/cobra"
Expand Down Expand Up @@ -81,7 +82,7 @@ func eventsAction(cmd *cobra.Command, args []string) error {
case "raw", "table", "wide":
return errors.New("unsupported format: \"raw\", \"table\", and \"wide\"")
default:
tmpl, err = parseTemplate(format)
tmpl, err = formatter.ParseTemplate(format)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/nerdctl/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func printHistory(cmd *cobra.Command, historys []historyPrintable) error {
return errors.New("format and quiet must not be specified together")
}
var err error
tmpl, err = parseTemplate(format)
tmpl, err = formatter.ParseTemplate(format)
if err != nil {
return err
}
Expand All @@ -214,7 +214,7 @@ func printHistory(cmd *cobra.Command, historys []historyPrintable) error {
}
}

if f, ok := w.(Flusher); ok {
if f, ok := w.(formatter.Flusher); ok {
return f.Flush()
}
return nil
Expand Down
8 changes: 6 additions & 2 deletions cmd/nerdctl/image_inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

"github.com/containerd/containerd"
"github.com/containerd/containerd/platforms"
"github.com/containerd/nerdctl/pkg/formatter"
"github.com/containerd/nerdctl/pkg/idutil/imagewalker"
"github.com/containerd/nerdctl/pkg/imageinspector"
"github.com/containerd/nerdctl/pkg/inspecttypes/dockercompat"
Expand Down Expand Up @@ -128,8 +129,11 @@ func imageInspectActionWithPlatform(cmd *cobra.Command, args []string, platform
if len(errs) > 0 {
return fmt.Errorf("%d errors: %v", len(errs), errs)
}

return formatSlice(cmd, f.entries)
format, err := cmd.Flags().GetString("format")
if err != nil {
return err
}
return formatter.FormatSlice(format, cmd.OutOrStdout(), f.entries)
}

type imageInspector struct {
Expand Down
4 changes: 2 additions & 2 deletions cmd/nerdctl/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ func printImages(ctx context.Context, cmd *cobra.Command, client *containerd.Cli
return errors.New("format and quiet must not be specified together")
}
var err error
tmpl, err = parseTemplate(format)
tmpl, err = formatter.ParseTemplate(format)
if err != nil {
return err
}
Expand Down Expand Up @@ -295,7 +295,7 @@ func printImages(ctx context.Context, cmd *cobra.Command, client *containerd.Cli
logrus.Warn(err)
}
}
if f, ok := w.(Flusher); ok {
if f, ok := w.(formatter.Flusher); ok {
return f.Flush()
}
return nil
Expand Down
3 changes: 2 additions & 1 deletion cmd/nerdctl/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"strings"
"text/template"

"github.com/containerd/nerdctl/pkg/formatter"
"golang.org/x/text/cases"
"golang.org/x/text/language"

Expand Down Expand Up @@ -67,7 +68,7 @@ func infoAction(cmd *cobra.Command, args []string) error {
return err
}
if format != "" {
tmpl, err = parseTemplate(format)
tmpl, err = formatter.ParseTemplate(format)
if err != nil {
return err
}
Expand Down
7 changes: 6 additions & 1 deletion cmd/nerdctl/namespace_inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package main

import (
"github.com/containerd/containerd/namespaces"
"github.com/containerd/nerdctl/pkg/formatter"
"github.com/containerd/nerdctl/pkg/inspecttypes/native"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -58,5 +59,9 @@ func labelInspectAction(cmd *cobra.Command, args []string) error {
}
result[index] = nsInspect
}
return formatSlice(cmd, result)
format, err := cmd.Flags().GetString("format")
if err != nil {
return err
}
return formatter.FormatSlice(format, cmd.OutOrStdout(), result)
}
8 changes: 6 additions & 2 deletions cmd/nerdctl/network_inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"encoding/json"
"fmt"

"github.com/containerd/nerdctl/pkg/formatter"
"github.com/containerd/nerdctl/pkg/inspecttypes/dockercompat"
"github.com/containerd/nerdctl/pkg/inspecttypes/native"
"github.com/containerd/nerdctl/pkg/netutil"
Expand Down Expand Up @@ -100,8 +101,11 @@ func networkInspectAction(cmd *cobra.Command, args []string) error {
return fmt.Errorf("unknown mode %q", mode)
}
}

return formatSlice(cmd, result)
format, err := cmd.Flags().GetString("format")
if err != nil {
return err
}
return formatter.FormatSlice(format, cmd.OutOrStdout(), result)
}

func networkInspectShellComplete(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
Expand Down
7 changes: 4 additions & 3 deletions cmd/nerdctl/network_ls.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"text/tabwriter"
"text/template"

"github.com/containerd/nerdctl/pkg/formatter"
"github.com/containerd/nerdctl/pkg/netutil"

"github.com/spf13/cobra"
Expand Down Expand Up @@ -79,7 +80,7 @@ func networkLsAction(cmd *cobra.Command, args []string) error {
return errors.New("format and quiet must not be specified together")
}
var err error
tmpl, err = parseTemplate(format)
tmpl, err = formatter.ParseTemplate(format)
if err != nil {
return err
}
Expand Down Expand Up @@ -114,7 +115,7 @@ func networkLsAction(cmd *cobra.Command, args []string) error {
}
}
if n.NerdctlLabels != nil {
p.Labels = formatLabels(*n.NerdctlLabels)
p.Labels = formatter.FormatLabels(*n.NerdctlLabels)
}
pp[i] = p
}
Expand Down Expand Up @@ -146,7 +147,7 @@ func networkLsAction(cmd *cobra.Command, args []string) error {
fmt.Fprintf(w, "%s\t%s\t%s\n", p.ID, p.Name, p.file)
}
}
if f, ok := w.(Flusher); ok {
if f, ok := w.(formatter.Flusher); ok {
return f.Flush()
}
return nil
Expand Down
4 changes: 2 additions & 2 deletions cmd/nerdctl/ps.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func printContainers(ctx context.Context, client *containerd.Client, cmd *cobra.
return errors.New("format and quiet must not be specified together")
}
var err error
tmpl, err = parseTemplate(format)
tmpl, err = formatter.ParseTemplate(format)
if err != nil {
return err
}
Expand Down Expand Up @@ -277,7 +277,7 @@ func printContainers(ctx context.Context, client *containerd.Client, cmd *cobra.
}

}
if f, ok := w.(Flusher); ok {
if f, ok := w.(formatter.Flusher); ok {
return f.Flush()
}
return nil
Expand Down
4 changes: 2 additions & 2 deletions cmd/nerdctl/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func statsAction(cmd *cobra.Command, args []string) error {
case "raw":
return errors.New("unsupported format: \"raw\"")
default:
tmpl, err = parseTemplate(format)
tmpl, err = formatter.ParseTemplate(format)
if err != nil {
return err
}
Expand Down Expand Up @@ -348,7 +348,7 @@ func statsAction(cmd *cobra.Command, args []string) error {
}
}
}
if f, ok := w.(Flusher); ok {
if f, ok := w.(formatter.Flusher); ok {
f.Flush()
}

Expand Down
3 changes: 2 additions & 1 deletion cmd/nerdctl/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"os"
"text/template"

"github.com/containerd/nerdctl/pkg/formatter"
"github.com/containerd/nerdctl/pkg/infoutil"
"github.com/containerd/nerdctl/pkg/inspecttypes/dockercompat"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -54,7 +55,7 @@ func versionAction(cmd *cobra.Command, args []string) error {
}
if format != "" {
var err error
tmpl, err = parseTemplate(format)
tmpl, err = formatter.ParseTemplate(format)
if err != nil {
return err
}
Expand Down
7 changes: 6 additions & 1 deletion cmd/nerdctl/volume_inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package main

import (
"github.com/containerd/nerdctl/pkg/formatter"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -57,8 +58,12 @@ func volumeInspectAction(cmd *cobra.Command, args []string) error {
}
result[i] = vol
}
format, err := cmd.Flags().GetString("format")
if err != nil {
return err
}

return formatSlice(cmd, result)
return formatter.FormatSlice(format, cmd.OutOrStdout(), result)
}

func volumeInspectShellComplete(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
Expand Down
7 changes: 4 additions & 3 deletions cmd/nerdctl/volume_ls.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"text/template"

"github.com/containerd/containerd/pkg/progress"
"github.com/containerd/nerdctl/pkg/formatter"
"github.com/containerd/nerdctl/pkg/inspecttypes/native"
"github.com/sirupsen/logrus"

Expand Down Expand Up @@ -116,7 +117,7 @@ func volumeLsAction(cmd *cobra.Command, args []string) error {
return errors.New("format and quiet must not be specified together")
}
var err error
tmpl, err = parseTemplate(format)
tmpl, err = formatter.ParseTemplate(format)
if err != nil {
return err
}
Expand All @@ -139,7 +140,7 @@ func volumeLsAction(cmd *cobra.Command, args []string) error {
Scope: "local",
}
if v.Labels != nil {
p.Labels = formatLabels(*v.Labels)
p.Labels = formatter.FormatLabels(*v.Labels)
}
if volumeSize {
p.Size = progress.Bytes(v.Size).String()
Expand All @@ -160,7 +161,7 @@ func volumeLsAction(cmd *cobra.Command, args []string) error {
fmt.Fprintf(w, "%s\t%s\n", p.Name, p.Mountpoint)
}
}
if f, ok := w.(Flusher); ok {
if f, ok := w.(formatter.Flusher); ok {
return f.Flush()
}
return nil
Expand Down
Loading