Add truncate function for Go templates#30484
Conversation
3f4db31 to
5ccc8bb
Compare
vdemeester
left a comment
There was a problem hiding this comment.
Design LGTM 🐮
/cc @thaJeztah @dnephin @cpuguy83 @tiborvass @AkihiroSuda @runcom @icecrime
|
LGTM |
dnephin
left a comment
There was a problem hiding this comment.
The tests could use the assertion helpers. I think it makes them a lot easier to read when they are shorter.
The error messages are also consistent that way, and include things like "Expected no error, but got: ..."
pkg/templates/templates_test.go
Outdated
pkg/templates/templates_test.go
Outdated
There was a problem hiding this comment.
assert.NilError(t, tm.Execute(&b, "tupx5xzf6hvsrhnruz5cr8gwp"))
pkg/templates/templates_test.go
Outdated
There was a problem hiding this comment.
assert.Equal(t, b.String(), "tupx5xzf6hvs")
pkg/templates/templates.go
Outdated
There was a problem hiding this comment.
Since this works on any string, I think it should take an integer argument to shorten to a certain length
There was a problem hiding this comment.
That is not to say that TruncateID should take an argument ;)
5ccc8bb to
3dd0c8a
Compare
|
Thanks @dnephin the PR has been updated with unit tests using assertion helpers. Other tests in |
|
Thanks @cpuguy83 @vdemeester for the comment. Now |
|
The correct word your looking for is |
|
I agree that Moving it back to design for a bit |
|
We currently have I am thinking maybe we could consider |
|
👍 for |
This fix is part of the discussion in 28199 about using
`truncate` to replace `--no-trunc`.
As part of the fix, a new function `truncate` has been
added for Go templates so that it is possible to use
```
docker stack services --format "{{truncate .ID 5}}: {{.Mode}} {{.Replicas}}"
```
to show truncated ID.
A unit test has been added.
This fix is related to 28199.
Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
3dd0c8a to
7fa8d5e
Compare
shorten function for Go templatestruncate function for Go templates
|
Thanks all for the review. The PR has been updated with |
|
@cpuguy83 @dnephin @thaJeztah @vdemeester feel free to merge. |
This fix is part of the discussion in #28199 about using
truncateto replace--no-trunc.As part of the fix, a new function
truncatehas been added for Go templates so that it is possible to useto show truncated ID (limited by length).
A unit test has been added.
This fix is related to #28199.
Signed-off-by: Yong Tang yong.tang.github@outlook.com