cli/command/formatter: use alias/wrapper for TruncateID

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn
2025-07-25 17:13:19 +02:00
parent 4bd6b6897f
commit d63cae6f1c
3 changed files with 51 additions and 13 deletions

View File

@ -8,6 +8,7 @@ import (
"strings"
"unicode/utf8"
"github.com/moby/moby/client/pkg/stringid"
"golang.org/x/text/width"
)
@ -27,23 +28,12 @@ func charWidth(r rune) int {
}
}
const shortLen = 12
// TruncateID returns a shorthand version of a string identifier for presentation,
// after trimming digest algorithm prefix (if any).
//
// This function is a copy of [stringid.TruncateID] for presentation / formatting
// purposes.
//
// [stringid.TruncateID]: https://github.com/moby/moby/blob/v28.3.2/pkg/stringid/stringid.go#L19
// This function is a wrapper for [stringid.TruncateID] for convenience.
func TruncateID(id string) string {
if i := strings.IndexRune(id, ':'); i >= 0 {
id = id[i+1:]
}
if len(id) > shortLen {
id = id[:shortLen]
}
return id
return stringid.TruncateID(id)
}
// Ellipsis truncates a string to fit within maxDisplayWidth, and appends ellipsis (…).