Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

image/list: Add opt-in to --tree by default #5772

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
31 changes: 31 additions & 0 deletions cli/command/image/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"io"
"strconv"

"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
Expand Down Expand Up @@ -81,6 +82,8 @@ func runImages(ctx context.Context, dockerCLI command.Cli, options imagesOptions
filters.Add("reference", options.matchName)
}

options = applyListFeatures(dockerCLI, options)

if options.tree {
if options.quiet {
return errors.New("--quiet is not yet supported with --tree")
Expand Down Expand Up @@ -167,3 +170,31 @@ func printAmbiguousHint(stdErr io.Writer, matchName string) {
_, _ = fmt.Fprintf(stdErr, "\nNo images found matching %q: did you mean \"docker image %[1]s\"?\n", matchName)
}
}

// applyListFeatures checks for feature flags in the config file
// and adjusts the options accordingly.
// Supported features:
// image-tree => --tree option is implied when possible
func applyListFeatures(dockerCLI command.Cli, options imagesOptions) imagesOptions {
cfg := dockerCLI.ConfigFile()
var treeOptIn bool
if v, ok := cfg.Features["image-tree"]; ok {
enabled, err := strconv.ParseBool(v)
if err != nil {
return options
}
if enabled {
treeOptIn = true
}
}

if !options.tree && treeOptIn {
treeOptIn = !options.quiet
treeOptIn = treeOptIn && !options.noTrunc
treeOptIn = treeOptIn && !options.showDigests
treeOptIn = treeOptIn && options.format == ""
options.tree = treeOptIn
}

return options
}
Loading