MCPcopy Create free account
hub / github.com/containerd/nerdctl / lsPrintOutput

Function lsPrintOutput

pkg/cmd/volume/list.go:94–154  ·  view source on GitHub ↗
(vols map[string]native.Volume, options types.VolumeListOptions)

Source from the content-addressed store, hash-verified

92}
93
94func lsPrintOutput(vols map[string]native.Volume, options types.VolumeListOptions) error {
95 w := options.Stdout
96 var tmpl *template.Template
97 switch options.Format {
98 case "", "table", "wide":
99 w = tabwriter.NewWriter(w, 4, 8, 4, ' ', 0)
100 if !options.Quiet {
101 if options.Size {
102 fmt.Fprintln(w, "VOLUME NAME\tDIRECTORY\tSIZE")
103 } else {
104 fmt.Fprintln(w, "VOLUME NAME\tDIRECTORY")
105 }
106 }
107 case "raw":
108 return errors.New("unsupported format: \"raw\"")
109 default:
110 if options.Quiet {
111 return errors.New("format and quiet must not be specified together")
112 }
113 var err error
114 tmpl, err = formatter.ParseTemplate(options.Format)
115 if err != nil {
116 return err
117 }
118 }
119
120 for _, v := range vols {
121 p := volumePrintable{
122 Driver: "local",
123 Labels: "",
124 Mountpoint: v.Mountpoint,
125 Name: v.Name,
126 Scope: "local",
127 }
128 if v.Labels != nil {
129 p.Labels = formatter.FormatLabels(*v.Labels)
130 }
131 if options.Size {
132 p.Size = progress.Bytes(v.Size).String()
133 }
134 if tmpl != nil {
135 var b bytes.Buffer
136 if err := tmpl.Execute(&b, p); err != nil {
137 return err
138 }
139 if _, err := fmt.Fprintln(w, b.String()); err != nil {
140 return err
141 }
142 } else if options.Quiet {
143 fmt.Fprintln(w, p.Name)
144 } else if options.Size {
145 fmt.Fprintf(w, "%s\t%s\t%s\n", p.Name, p.Mountpoint, p.Size)
146 } else {
147 fmt.Fprintf(w, "%s\t%s\n", p.Name, p.Mountpoint)
148 }
149 }
150 if f, ok := w.(formatter.Flusher); ok {
151 return f.Flush()

Callers 1

ListFunction · 0.85

Calls 4

ParseTemplateFunction · 0.92
FormatLabelsFunction · 0.92
FlushMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…