Skip to content

Commit 5c0b9c0

Browse files
committed
cli/command/formatter: use alias/wrapper for TruncateID
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent 78ded0f commit 5c0b9c0

3 files changed

Lines changed: 51 additions & 13 deletions

File tree

cli/command/formatter/displayutils.go

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"strings"
99
"unicode/utf8"
1010

11+
"github.com/moby/moby/client/pkg/stringid"
1112
"golang.org/x/text/width"
1213
)
1314

@@ -27,23 +28,12 @@ func charWidth(r rune) int {
2728
}
2829
}
2930

30-
const shortLen = 12
31-
3231
// TruncateID returns a shorthand version of a string identifier for presentation,
3332
// after trimming digest algorithm prefix (if any).
3433
//
35-
// This function is a copy of [stringid.TruncateID] for presentation / formatting
36-
// purposes.
37-
//
38-
// [stringid.TruncateID]: https://github.com/moby/moby/blob/v28.3.2/pkg/stringid/stringid.go#L19
34+
// This function is a wrapper for [stringid.TruncateID] for convenience.
3935
func TruncateID(id string) string {
40-
if i := strings.IndexRune(id, ':'); i >= 0 {
41-
id = id[i+1:]
42-
}
43-
if len(id) > shortLen {
44-
id = id[:shortLen]
45-
}
46-
return id
36+
return stringid.TruncateID(id)
4737
}
4838

4939
// Ellipsis truncates a string to fit within maxDisplayWidth, and appends ellipsis (…).

vendor/github.com/moby/moby/client/pkg/stringid/stringid.go

Lines changed: 47 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/modules.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ github.com/moby/moby/api/types/volume
201201
# github.com/moby/moby/client v0.0.0 => github.com/moby/moby/client v0.0.0-20250726000215-c4afa7715715
202202
## explicit; go 1.23.0
203203
github.com/moby/moby/client
204+
github.com/moby/moby/client/pkg/stringid
204205
# github.com/moby/patternmatcher v0.6.0
205206
## explicit; go 1.19
206207
github.com/moby/patternmatcher

0 commit comments

Comments
 (0)