mirror of
https://github.com/podman-container-tools/podman.git
synced 2026-08-05 00:15:44 +00:00
Fixes: https://github.com/containers/podman/issues/21847 Signed-off-by: Jan Rodák <hony.com@seznam.cz>
21 lines
487 B
Go
21 lines
487 B
Go
package common
|
|
|
|
import (
|
|
"slices"
|
|
"strings"
|
|
)
|
|
|
|
// FormatLabels converts a map of labels to a sorted, comma-separated list
|
|
// of key=value pairs, matching Docker CLI output format.
|
|
func FormatLabels(labels map[string]string) string {
|
|
keys := make([]string, 0, len(labels))
|
|
for k := range labels {
|
|
keys = append(keys, k)
|
|
}
|
|
slices.Sort(keys)
|
|
list := make([]string, 0, len(keys))
|
|
for _, k := range keys {
|
|
list = append(list, k+"="+labels[k])
|
|
}
|
|
return strings.Join(list, ",")
|
|
}
|