CLI: Add missing `pad` and `truncate` output formatting functions (#22384)

See https://github.com/docker/cli/blob/master/templates/templates.go

---------

Co-authored-by: Usha Mandya <47779042+usha-mandya@users.noreply.github.com>
This commit is contained in:
stevenlele 2025-04-09 11:16:18 +00:00 committed by GitHub
parent b2950312d8
commit 01505f4d80
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 20 additions and 0 deletions

View File

@ -90,6 +90,26 @@ $ docker inspect --format "{{title .Name}}" container
$ docker inspect --format "{{upper .Name}}" container
```
## pad
`pad` adds whitespace padding to a string. You can specify the number of spaces to add before and after the string.
```console
$ docker image list --format '{{pad .Repository 5 10}}'
```
This example adds 5 spaces before the image repository name and 10 spaces after.
## truncate
`truncate` shortens a string to a specified length. If the string is shorter than the specified length, it remains unchanged.
```console
$ docker image list --format '{{truncate .Repository 15}}'
```
This example displays the image repository name, truncating it to the first 15 characters if it's longer.
## println
`println` prints each value on a new line.