@@ -26,7 +26,6 @@ type imagesOptions struct {
2626 showDigests bool
2727 format string
2828 filter opts.FilterOpt
29- calledAs string
3029 tree bool
3130}
3231
@@ -42,11 +41,14 @@ func newImagesCommand(dockerCLI command.Cli) *cobra.Command {
4241 if len (args ) > 0 {
4342 options .matchName = args [0 ]
4443 }
45- // Pass through how the command was invoked. We use this to print
46- // warnings when an ambiguous argument was passed when using the
47- // legacy (top-level) "docker images" subcommand.
48- options .calledAs = cmd .CalledAs ()
49- return runImages (cmd .Context (), dockerCLI , options )
44+ numImages , err := runImages (cmd .Context (), dockerCLI , options )
45+ if err != nil {
46+ return err
47+ }
48+ if numImages == 0 && options .matchName != "" && cmd .CalledAs () == "images" {
49+ printAmbiguousHint (dockerCLI .Err (), options .matchName )
50+ }
51+ return nil
5052 },
5153 Annotations : map [string ]string {
5254 "category-top" : "7" ,
@@ -79,15 +81,15 @@ func newListCommand(dockerCLI command.Cli) *cobra.Command {
7981 return & cmd
8082}
8183
82- func runImages (ctx context.Context , dockerCLI command.Cli , options imagesOptions ) error {
84+ func runImages (ctx context.Context , dockerCLI command.Cli , options imagesOptions ) ( int , error ) {
8385 filters := options .filter .Value ()
8486 if options .matchName != "" {
8587 filters .Add ("reference" , options .matchName )
8688 }
8789
8890 useTree , err := shouldUseTree (options )
8991 if err != nil {
90- return err
92+ return 0 , err
9193 }
9294
9395 if useTree {
@@ -103,7 +105,7 @@ func runImages(ctx context.Context, dockerCLI command.Cli, options imagesOptions
103105 Filters : filters ,
104106 })
105107 if err != nil {
106- return err
108+ return 0 , err
107109 }
108110
109111 format := options .format
@@ -124,12 +126,9 @@ func runImages(ctx context.Context, dockerCLI command.Cli, options imagesOptions
124126 Digest : options .showDigests ,
125127 }
126128 if err := formatter .ImageWrite (imageCtx , images ); err != nil {
127- return err
128- }
129- if options .matchName != "" && len (images ) == 0 && options .calledAs == "images" {
130- printAmbiguousHint (dockerCLI .Err (), options .matchName )
129+ return 0 , err
131130 }
132- return nil
131+ return len ( images ), nil
133132}
134133
135134func shouldUseTree (options imagesOptions ) (bool , error ) {
0 commit comments