@@ -199,37 +199,50 @@ var setLabelsCommand = cli.Command{
199199
200200var checkCommand = cli.Command {
201201 Name : "check" ,
202- Usage : "check that an image has all content available locally" ,
202+ Usage : "check existing images to ensure all content is available locally" ,
203203 ArgsUsage : "[flags] [<filter>, ...]" ,
204- Description : "check that an image has all content available locally" ,
205- Flags : commands .SnapshotterFlags ,
204+ Description : "check existing images to ensure all content is available locally" ,
205+ Flags : append ([]cli.Flag {
206+ cli.BoolFlag {
207+ Name : "quiet, q" ,
208+ Usage : "print only the ready image refs (fully downloaded and unpacked)" ,
209+ },
210+ }, commands .SnapshotterFlags ... ),
206211 Action : func (context * cli.Context ) error {
207212 var (
208213 exitErr error
214+ quiet = context .Bool ("quiet" )
209215 )
210216 client , ctx , cancel , err := commands .NewClient (context )
211217 if err != nil {
212218 return err
213219 }
214220 defer cancel ()
215- var (
216- contentStore = client .ContentStore ()
217- tw = tabwriter .NewWriter (os .Stdout , 1 , 8 , 1 , ' ' , 0 )
218- )
219- fmt .Fprintln (tw , "REF\t TYPE\t DIGEST\t STATUS\t SIZE\t UNPACKED\t " )
221+
222+ var contentStore = client .ContentStore ()
220223
221224 args := []string (context .Args ())
222225 imageList , err := client .ListImages (ctx , args ... )
223226 if err != nil {
224227 return errors .Wrap (err , "failed listing images" )
225228 }
229+ if len (imageList ) == 0 {
230+ log .G (ctx ).Debugf ("no images found" )
231+ return exitErr
232+ }
233+
234+ var tw = tabwriter .NewWriter (os .Stdout , 1 , 8 , 1 , ' ' , 0 )
235+ if ! quiet {
236+ fmt .Fprintln (tw , "REF\t TYPE\t DIGEST\t STATUS\t SIZE\t UNPACKED\t " )
237+ }
226238
227239 for _ , image := range imageList {
228240 var (
229241 status string = "complete"
230242 size string
231243 requiredSize int64
232244 presentSize int64
245+ complete bool = true
233246 )
234247
235248 available , required , present , missing , err := images .Check (ctx , contentStore , image .Target (), platforms .Default ())
@@ -239,6 +252,7 @@ var checkCommand = cli.Command{
239252 }
240253 log .G (ctx ).WithError (err ).Errorf ("unable to check %v" , image .Name ())
241254 status = "error"
255+ complete = false
242256 }
243257
244258 if status != "error" {
@@ -252,6 +266,7 @@ var checkCommand = cli.Command{
252266
253267 if len (missing ) > 0 {
254268 status = "incomplete"
269+ complete = false
255270 }
256271
257272 if available {
@@ -260,6 +275,7 @@ var checkCommand = cli.Command{
260275 } else {
261276 status = fmt .Sprintf ("unavailable (%v/?)" , len (present ))
262277 size = fmt .Sprintf ("%v/?" , progress .Bytes (presentSize ))
278+ complete = false
263279 }
264280 } else {
265281 size = "-"
@@ -273,16 +289,23 @@ var checkCommand = cli.Command{
273289 log .G (ctx ).WithError (err ).Errorf ("unable to check unpack for %v" , image .Name ())
274290 }
275291
276- fmt .Fprintf (tw , "%v\t %v\t %v\t %v\t %v\t %t\n " ,
277- image .Name (),
278- image .Target ().MediaType ,
279- image .Target ().Digest ,
280- status ,
281- size ,
282- unpacked )
292+ if ! quiet {
293+ fmt .Fprintf (tw , "%v\t %v\t %v\t %v\t %v\t %t\n " ,
294+ image .Name (),
295+ image .Target ().MediaType ,
296+ image .Target ().Digest ,
297+ status ,
298+ size ,
299+ unpacked )
300+ } else {
301+ if complete {
302+ fmt .Println (image .Name ())
303+ }
304+ }
305+ }
306+ if ! quiet {
307+ tw .Flush ()
283308 }
284- tw .Flush ()
285-
286309 return exitErr
287310 },
288311}
0 commit comments