From 4804824c78a8f09e4e84585b2d3e6ccf89197f79 Mon Sep 17 00:00:00 2001 From: Tonis Tiigi Date: Fri, 24 Apr 2020 20:08:43 -0700 Subject: [PATCH] separate manual and automatically detected platforms Signed-off-by: Tonis Tiigi --- commands/inspect.go | 2 +- commands/ls.go | 3 +-- util/platformutil/parse.go | 21 +++++++++++++++++++++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/commands/inspect.go b/commands/inspect.go index ccf53961..fba2a695 100644 --- a/commands/inspect.go +++ b/commands/inspect.go @@ -117,7 +117,7 @@ func runInspect(dockerCli command.Cli, in inspectOptions, args []string) error { if len(n.Flags) > 0 { fmt.Fprintf(w, "Flags:\t%s\n", strings.Join(n.Flags, " ")) } - fmt.Fprintf(w, "Platforms:\t%s\n", strings.Join(platformutil.Format(platformutil.Dedupe(append(n.Platforms, ngi.drivers[i].platforms...))), ", ")) + fmt.Fprintf(w, "Platforms:\t%s\n", strings.Join(platformutil.FormatInGroups(n.Platforms, ngi.drivers[i].platforms), ", ")) } } } diff --git a/commands/ls.go b/commands/ls.go index 14baa0bb..bf927c4b 100644 --- a/commands/ls.go +++ b/commands/ls.go @@ -126,11 +126,10 @@ func printngi(w io.Writer, ngi *nginfo) { if d.info != nil { status = d.info.Status.String() } - p := append(n.Platforms, d.platforms...) if err != "" { fmt.Fprintf(w, " %s\t%s\t%s\n", n.Name, n.Endpoint, err) } else { - fmt.Fprintf(w, " %s\t%s\t%s\t%s\n", n.Name, n.Endpoint, status, strings.Join(platformutil.Format(p), ", ")) + fmt.Fprintf(w, " %s\t%s\t%s\t%s\n", n.Name, n.Endpoint, status, strings.Join(platformutil.FormatInGroups(n.Platforms, d.platforms), ", ")) } } } diff --git a/util/platformutil/parse.go b/util/platformutil/parse.go index d1bc9a50..c17a77cc 100644 --- a/util/platformutil/parse.go +++ b/util/platformutil/parse.go @@ -53,6 +53,27 @@ func Dedupe(in []specs.Platform) []specs.Platform { return out } +func FormatInGroups(gg ...[]specs.Platform) []string { + m := map[string]struct{}{} + out := make([]string, 0, len(gg)) + for i, g := range gg { + for _, p := range g { + p := platforms.Normalize(p) + key := platforms.Format(p) + if _, ok := m[key]; ok { + continue + } + m[key] = struct{}{} + v := platforms.Format(p) + if i == 0 { + v += "*" + } + out = append(out, v) + } + } + return out +} + func Format(in []specs.Platform) []string { if len(in) == 0 { return nil