@@ -30,7 +30,6 @@ import (
3030 "github.com/containerd/containerd/log"
3131 "github.com/containerd/containerd/pkg/progress"
3232 "github.com/containerd/containerd/platforms"
33-
3433 "github.com/urfave/cli"
3534)
3635
@@ -202,37 +201,50 @@ var setLabelsCommand = cli.Command{
202201
203202var checkCommand = cli.Command {
204203 Name : "check" ,
205- Usage : "check that an image has all content available locally" ,
204+ Usage : "check existing images to ensure all content is available locally" ,
206205 ArgsUsage : "[flags] [<filter>, ...]" ,
207- Description : "check that an image has all content available locally" ,
208- Flags : commands .SnapshotterFlags ,
206+ Description : "check existing images to ensure all content is available locally" ,
207+ Flags : append ([]cli.Flag {
208+ cli.BoolFlag {
209+ Name : "quiet, q" ,
210+ Usage : "print only the ready image refs (fully downloaded and unpacked)" ,
211+ },
212+ }, commands .SnapshotterFlags ... ),
209213 Action : func (context * cli.Context ) error {
210214 var (
211215 exitErr error
216+ quiet = context .Bool ("quiet" )
212217 )
213218 client , ctx , cancel , err := commands .NewClient (context )
214219 if err != nil {
215220 return err
216221 }
217222 defer cancel ()
218- var (
219- contentStore = client .ContentStore ()
220- tw = tabwriter .NewWriter (os .Stdout , 1 , 8 , 1 , ' ' , 0 )
221- )
222- fmt .Fprintln (tw , "REF\t TYPE\t DIGEST\t STATUS\t SIZE\t UNPACKED\t " )
223+
224+ var contentStore = client .ContentStore ()
223225
224226 args := []string (context .Args ())
225227 imageList , err := client .ListImages (ctx , args ... )
226228 if err != nil {
227229 return fmt .Errorf ("failed listing images: %w" , err )
228230 }
231+ if len (imageList ) == 0 {
232+ log .G (ctx ).Debugf ("no images found" )
233+ return exitErr
234+ }
235+
236+ var tw = tabwriter .NewWriter (os .Stdout , 1 , 8 , 1 , ' ' , 0 )
237+ if ! quiet {
238+ fmt .Fprintln (tw , "REF\t TYPE\t DIGEST\t STATUS\t SIZE\t UNPACKED\t " )
239+ }
229240
230241 for _ , image := range imageList {
231242 var (
232243 status string = "complete"
233244 size string
234245 requiredSize int64
235246 presentSize int64
247+ complete bool = true
236248 )
237249
238250 available , required , present , missing , err := images .Check (ctx , contentStore , image .Target (), platforms .Default ())
@@ -242,6 +254,7 @@ var checkCommand = cli.Command{
242254 }
243255 log .G (ctx ).WithError (err ).Errorf ("unable to check %v" , image .Name ())
244256 status = "error"
257+ complete = false
245258 }
246259
247260 if status != "error" {
@@ -255,6 +268,7 @@ var checkCommand = cli.Command{
255268
256269 if len (missing ) > 0 {
257270 status = "incomplete"
271+ complete = false
258272 }
259273
260274 if available {
@@ -263,6 +277,7 @@ var checkCommand = cli.Command{
263277 } else {
264278 status = fmt .Sprintf ("unavailable (%v/?)" , len (present ))
265279 size = fmt .Sprintf ("%v/?" , progress .Bytes (presentSize ))
280+ complete = false
266281 }
267282 } else {
268283 size = "-"
@@ -276,23 +291,30 @@ var checkCommand = cli.Command{
276291 log .G (ctx ).WithError (err ).Errorf ("unable to check unpack for %v" , image .Name ())
277292 }
278293
279- fmt .Fprintf (tw , "%v\t %v\t %v\t %v\t %v\t %t\n " ,
280- image .Name (),
281- image .Target ().MediaType ,
282- image .Target ().Digest ,
283- status ,
284- size ,
285- unpacked )
294+ if ! quiet {
295+ fmt .Fprintf (tw , "%v\t %v\t %v\t %v\t %v\t %t\n " ,
296+ image .Name (),
297+ image .Target ().MediaType ,
298+ image .Target ().Digest ,
299+ status ,
300+ size ,
301+ unpacked )
302+ } else {
303+ if complete {
304+ fmt .Println (image .Name ())
305+ }
306+ }
307+ }
308+ if ! quiet {
309+ tw .Flush ()
286310 }
287- tw .Flush ()
288-
289311 return exitErr
290312 },
291313}
292314
293315var removeCommand = cli.Command {
294- Name : "remove " ,
295- Aliases : []string {"rm" },
316+ Name : "delete " ,
317+ Aliases : []string {"del" , "remove" , " rm" },
296318 Usage : "remove one or more images by reference" ,
297319 ArgsUsage : "[flags] <ref> [<ref>, ...]" ,
298320 Description : "remove one or more images by reference" ,
0 commit comments