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
26 changes: 26 additions & 0 deletions cli/command/image/list.go
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,6 +2,7 @@ package image

import (
"context"
"errors"
"fmt"
"io"

Expand All@@ -24,6 +25,7 @@ type imagesOptions struct {
format string
filter opts.FilterOpt
calledAs string
tree bool
}

// NewImagesCommand creates a new `docker images` command
Expand DownExpand Up@@ -59,6 +61,10 @@ func NewImagesCommand(dockerCLI command.Cli) *cobra.Command {
flags.StringVar(&options.format, "format", "", flagsHelper.FormatHelp)
flags.VarP(&options.filter, "filter", "f", "Filter output based on conditions provided")

flags.BoolVar(&options.tree, "tree", false, "List multi-platform images as a tree (EXPERIMENTAL)")
flags.SetAnnotation("tree", "version", []string{"1.47"})
flags.SetAnnotation("tree", "experimentalCLI", nil)

return cmd
}

Expand All@@ -75,6 +81,26 @@ func runImages(ctx context.Context, dockerCLI command.Cli, options imagesOptions
filters.Add("reference", options.matchName)
}

if options.tree {
if options.quiet {
return errors.New("--quiet is not yet supported with --tree")
}
Comment on lines +84 to +87

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably OK for now (i.e., producing an error); we may have to look what we want the behavior to be. I think for other cases we made the quiet always work; i.e. --format .... --quiet would continue to just print the ID (digest) of the image.

if options.noTrunc {
return errors.New("--no-trunc is not yet supported with --tree")
}
if options.showDigests {
return errors.New("--show-digest is not yet supported with --tree")
}
if options.format != "" {
return errors.New("--format is not yet supported with --tree")
}
Comment on lines +94 to +96

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also slightly wondering if we should use --format=tree for this (although --tree could be a "porcelain" option for setting that) 🤔

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tree being a format would mean taking away the option to specify custom columns though.
Not sure if we want that?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Depends a bit on how it's implemented. For the default (table) output, we have --format=table to pick the default table output, but it takes arguments, so can be used to produce a custom table;

docker image ls --format=table
REPOSITORY TAG IMAGE ID CREATED SIZE
docker-cli-dev latest 88c125e27aee 21 hours ago 749MB
docker-dev latest 60f88d03ca84 4 days ago 2.21GB
golang 1.22 2bd56f00ff47 6 days ago 1.21GB
docker image ls --format "table {{.Tag}}\t{{.ID}}"
TAG IMAGE ID
latest 88c125e27aee
latest 60f88d03ca84
1.22 2bd56f00ff47


return runTree(ctx, dockerCLI, treeOptions{
all: options.all,
filters: filters,
})
}

images, err := dockerCLI.Client().ImageList(ctx, image.ListOptions{
All: options.all,
Filters: filters,
Expand Down
Loading