Nothing mergeable here, but this was me playing around; initially to see
if we could print the format such as suggested in https://github.com/docker/cli/issues/5560#issuecomment-2437212303
That output is shown in `TestTree`:
IMAGE/TAGS ID DISK USAGE CONTENT SIZE USED
alpine:latest beefdbd8a1da 13.6MB 4.09MB
├─ linux/amd64 33735bd63cf8 0B 0B
├─ linux/arm/v6 50f635c8b04d 0B 0B
├─ linux/arm/v7 f2f82d424957 0B 0B
├─ linux/arm64/v8 9cee2b382fe2 13.6MB 4.09MB
├─ linux/386 b3e87f642f5c 0B 0B
├─ linux/ppc64le c7a6800e3dc5 0B 0B
├─ linux/riscv64 80cde017a105 0B 0B
└─ linux/s390x 2b5b26e09ca2 0B 0B
namespace/image beefdbd8a1da 13.6MB 4.09MB
├─ namespace/image:1 beefdbd8a1da - -
├─ namespace/image:1.0 beefdbd8a1da - -
├─ namespace/image:1.0.0 beefdbd8a1da - -
└─ namespace/image:latest beefdbd8a1da - -
├─ linux/amd64 33735bd63cf8 0B 0B
├─ linux/arm/v6 50f635c8b04d 0B 0B
├─ linux/arm/v7 f2f82d424957 0B 0B
├─ linux/arm64/v8 9cee2b382fe2 13.6MB 4.09MB
├─ linux/386 b3e87f642f5c 0B 0B
├─ linux/ppc64le c7a6800e3dc5 0B 0B
├─ linux/riscv64 80cde017a105 0B 0B
└─ linux/s390x 2b5b26e09ca2 0B 0B
internal.example.com/namespace/image beefdbd8a1da 13.6MB 4.09MB
├─ internal.example.com/namespace/image:1 beefdbd8a1da - -
├─ internal.example.com/namespace/image:1.0 beefdbd8a1da - -
├─ internal.example.com/namespace/image:1.0.0 beefdbd8a1da - -
└─ internal.example.com/namespace/image:latest beefdbd8a1da - -
├─ linux/amd64 33735bd63cf8 0B 0B
├─ linux/arm/v6 50f635c8b04d 0B 0B
├─ linux/arm/v7 f2f82d424957 0B 0B
├─ linux/arm64/v8 9cee2b382fe2 13.6MB 4.09MB
├─ linux/386 b3e87f642f5c 0B 0B
├─ linux/ppc64le c7a6800e3dc5 0B 0B
├─ linux/riscv64 80cde017a105 0B 0B
└─ linux/s390x 2b5b26e09ca2 0B 0B
And `TestTreeNoTrunc` (non-truncated):
IMAGE/TAGS ID DISK USAGE CONTENT SIZE USED
alpine:latest sha256:beefdbd8a1da6d2915566fde36db9db0b524eb737fc57cd1367effd16dc0d06d 13.6MB 4.09MB
├─ linux/amd64 sha256:33735bd63cf84d7e388d9f6d297d348c523c044410f553bd878c6d7829612735 0B 0B
├─ linux/arm/v6 sha256:50f635c8b04d86dde8a02bcd8d667ba287eb8b318c1c0cf547e5a48ddadea1be 0B 0B
├─ linux/arm/v7 sha256:f2f82d42495723c4dc508fd6b0978a5d7fe4efcca4282e7aae5e00bcf4057086 0B 0B
├─ linux/arm64/v8 sha256:9cee2b382fe2412cd77d5d437d15a93da8de373813621f2e4d406e3df0cf0e7c 13.6MB 4.09MB
├─ linux/386 sha256:b3e87f642f5c48cdc7556c3e03a0d63916bd0055ba6edba7773df3cb1a76f224 0B 0B
├─ linux/ppc64le sha256:c7a6800e3dc569a2d6e90627a2988f2a7339e6f111cdf6a0054ad1ff833e99b0 0B 0B
├─ linux/riscv64 sha256:80cde017a10529a18a7274f70c687bb07c4969980ddfb35a1b921fda3a020e5b 0B 0B
└─ linux/s390x sha256:2b5b26e09ca2856f50ac88312348d26c1ac4b8af1df9f580e5cf465fd76e3d4d 0B 0B
namespace/image sha256:beefdbd8a1da6d2915566fde36db9db0b524eb737fc57cd1367effd16dc0d06d 13.6MB 4.09MB
├─ namespace/image:1 sha256:beefdbd8a1da6d2915566fde36db9db0b524eb737fc57cd1367effd16dc0d06d - -
├─ namespace/image:1.0 sha256:beefdbd8a1da6d2915566fde36db9db0b524eb737fc57cd1367effd16dc0d06d - -
├─ namespace/image:1.0.0 sha256:beefdbd8a1da6d2915566fde36db9db0b524eb737fc57cd1367effd16dc0d06d - -
└─ namespace/image:latest sha256:beefdbd8a1da6d2915566fde36db9db0b524eb737fc57cd1367effd16dc0d06d - -
├─ linux/amd64 sha256:33735bd63cf84d7e388d9f6d297d348c523c044410f553bd878c6d7829612735 0B 0B
├─ linux/arm/v6 sha256:50f635c8b04d86dde8a02bcd8d667ba287eb8b318c1c0cf547e5a48ddadea1be 0B 0B
├─ linux/arm/v7 sha256:f2f82d42495723c4dc508fd6b0978a5d7fe4efcca4282e7aae5e00bcf4057086 0B 0B
├─ linux/arm64/v8 sha256:9cee2b382fe2412cd77d5d437d15a93da8de373813621f2e4d406e3df0cf0e7c 13.6MB 4.09MB
├─ linux/386 sha256:b3e87f642f5c48cdc7556c3e03a0d63916bd0055ba6edba7773df3cb1a76f224 0B 0B
├─ linux/ppc64le sha256:c7a6800e3dc569a2d6e90627a2988f2a7339e6f111cdf6a0054ad1ff833e99b0 0B 0B
├─ linux/riscv64 sha256:80cde017a10529a18a7274f70c687bb07c4969980ddfb35a1b921fda3a020e5b 0B 0B
└─ linux/s390x sha256:2b5b26e09ca2856f50ac88312348d26c1ac4b8af1df9f580e5cf465fd76e3d4d 0B 0B
internal.example.com/namespace/image sha256:beefdbd8a1da6d2915566fde36db9db0b524eb737fc57cd1367effd16dc0d06d 13.6MB 4.09MB
├─ internal.example.com/namespace/image:1 sha256:beefdbd8a1da6d2915566fde36db9db0b524eb737fc57cd1367effd16dc0d06d - -
├─ internal.example.com/namespace/image:1.0 sha256:beefdbd8a1da6d2915566fde36db9db0b524eb737fc57cd1367effd16dc0d06d - -
├─ internal.example.com/namespace/image:1.0.0 sha256:beefdbd8a1da6d2915566fde36db9db0b524eb737fc57cd1367effd16dc0d06d - -
└─ internal.example.com/namespace/image:latest sha256:beefdbd8a1da6d2915566fde36db9db0b524eb737fc57cd1367effd16dc0d06d - -
├─ linux/amd64 sha256:33735bd63cf84d7e388d9f6d297d348c523c044410f553bd878c6d7829612735 0B 0B
├─ linux/arm/v6 sha256:50f635c8b04d86dde8a02bcd8d667ba287eb8b318c1c0cf547e5a48ddadea1be 0B 0B
├─ linux/arm/v7 sha256:f2f82d42495723c4dc508fd6b0978a5d7fe4efcca4282e7aae5e00bcf4057086 0B 0B
├─ linux/arm64/v8 sha256:9cee2b382fe2412cd77d5d437d15a93da8de373813621f2e4d406e3df0cf0e7c 13.6MB 4.09MB
├─ linux/386 sha256:b3e87f642f5c48cdc7556c3e03a0d63916bd0055ba6edba7773df3cb1a76f224 0B 0B
├─ linux/ppc64le sha256:c7a6800e3dc569a2d6e90627a2988f2a7339e6f111cdf6a0054ad1ff833e99b0 0B 0B
├─ linux/riscv64 sha256:80cde017a10529a18a7274f70c687bb07c4969980ddfb35a1b921fda3a020e5b 0B 0B
└─ linux/s390x sha256:2b5b26e09ca2856f50ac88312348d26c1ac4b8af1df9f580e5cf465fd76e3d4d 0B 0B
The above is all without the nice color-formatting etc, but this would be handled
before this;
The second bit was to see if we could make the tree output more align
with other output formats;
- Most of our commands allow passing a `--format`, including for (e.g.) `table`
- We want the tree view to also support, e.g. `--no-trunc`, which means that
some columns will be wider.
- If we use a tabwriter for printing, we can have it handle the column-sizing
for us.
- And if we do, we could let the user pass a custom format, and still print
it as a tree.
e.g., a format could be;
--format 'tree {.Image}}\t{{.Digest}}\t{{.InUse}}'
Which would output something like
IMAGE ID USED
alpine:latest beefdbd8a1da ✔
├─ linux/amd64 33735bd63cf8
├─ linux/arm/v6 50f635c8b04d
├─ linux/arm/v7 f2f82d424957
├─ linux/arm64/v8 9cee2b382fe2 ✔
├─ linux/386 b3e87f642f5c
├─ linux/ppc64le c7a6800e3dc5
├─ linux/riscv64 80cde017a105
└─ linux/s390x 2b5b26e09ca2
The `TestTree` implementation is really quirky though, as it uses a `[][]string`,
which won't work well if we want to make it more generic (with an "unknown"
depth); probably needs some type defined that has an optional slice for child
rows; those child-rows can be pre-formatted.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
The docker inspect command did not inspect configs. This patch adds support for
it, and while at it, also sorts the list of objects in runInspect.
Before this patch:
docker config create myconfig ./codecov.yml
danpeyh8qzb30vgdj9fr665l1
docker inspect --format='{{.ID}}' myconfig
[]
Error: No such object: myconfig
docker inspect --format='{{.ID}}' --type=config myconfig
"config" is not a valid value for --type
With this patch:
docker inspect --format='{{.ID}}' myconfig
danpeyh8qzb30vgdj9fr665l1
docker inspect --format='{{.ID}}' --type=config myconfig
danpeyh8qzb30vgdj9fr665l1
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This function was names slightly confusing, as it returns a fakeStore,
and it didn't do any constructing, so didn't provide value above just
constructing the type.
I'm planning to add more functionality to the fakeStore, but don't want
to maintain a full-fledged constructor for all of that, so let's remove
this utility.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
The Errors type was deprecated in d3bafa5f3e,
which has been included in the 27.4.0 release.
This patch removes the type, as there are no external consumers.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
The format had a stray colon and space included. While fixing that, also
updating the error message to clarify the error happened while parsing
the file (not so much "loading" it).
Before:
WARNING: Error loading config file: /root/.docker/config.json: : json: cannot unmarshal bool into Go struct field ConfigFile.features of type string
After:
WARNING: Error parsing config file (/root/.docker/config.json): json: cannot unmarshal bool into Go struct field ConfigFile.features of type string
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Before this change, the config-file was always updated, even if there
were no changes to save. This could cause issues when the config-file
already had credentials set and was read-only for the current user.
For example, on NixOS, this poses a problem because `config.json` is a
symlink to a write-protected file;
$ readlink ~/.docker/config.json
/home/username/.config/sops-nix/secrets/ghcr_auth
$ readlink -f ~/.docker/config.json
/run/user/1000/secrets.d/28/ghcr_auth
Which causes `docker login` to fail, even if no changes were to be made;
Error saving credentials: rename /home/derek/.docker/config.json2180380217 /home/username/.config/sops-nix/secrets/ghcr_auth: invalid cross-device link
This patch updates the code to only update the config file if changes
were detected. It there's nothing to save, it skips updating the file,
as well as skips printing the warning about credentials being stored
insecurely.
With this patch applied:
$ docker login -u yourname
Password:
WARNING! Your credentials are stored unencrypted in '/root/.docker/config.json'.
Configure a credential helper to remove this warning. See
https://docs.docker.com/go/credential-store/
Login Succeeded
$ docker login -u yourname
Password:
Login Succeeded
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This message resulted in code-lines that were too long; move it to a
const together with the other hint. While at it, also suppress unhandled
error, and touch-up the code-comment.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Deprecation comments must have an empty line before them, otherwise tools
and linters may not recognise them. While fixing this, also updated the
reference to PromptUserForCredentials to be a docs-link to make it clickable.
Updates 6e4818e7d6.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
If restoring the terminal state fails, "echo" no longer works, which means
that anything the user types is no longer shown. The login itself may already
have succeeded, so we should not fail the command, but it's good to inform
the user that this happened, which may give them a clue why things no longer
work as they expect them to work.
With this patch:
docker login -u yourname
Password:
Error: failed to restore terminal state to echo input: something bad happened
Login Succeeded
We should consider printing instructions how to restore this manually (other
than restarting the shell). e.g., 'run stty echo' when in a Linux or macOS shell,
but PowerShell and CMD.exe may need different instructions.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
we don't support empty passwords; when prompting the user for a password,
we already trim the result, but we didn't do the same for a password that's
passed through stdin or through the `-p` / `--password` flag.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
- move trimming defaultUsername inside the if-branch, as it's the only
location where the result of the trimmed username is use.
- do the reverse for trimming argUser, because the result of trimming
argUser is used outside of the if-branch (not just for the condition).
putting it inside the condition makes it easy to assume the result is
only used locally.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
move the "post" check for username being empty inside the branch
that's handling the username, as it's the only branch where username
is mutated after checking if it's empty.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
remove isDefaultRegistry and inline it where it's used; the code-comment
already outlines what we're looking for, so the intermediate var didn't
add much currently.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This function has multiple conditional branches, which makes it harder
to see at a glance whether authConfig may be partially populated. This
patch instead returns a fresh instance for error returns to prevent any
confusion.
It also removes the named output variables, as they're now no longer used,
and the returned types should already be descriptive enough to understand
what's returned.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
The Errors type is no longer used by the CLI itself, and this custom
"multi-error" implementation had both limitations (empty list not being
`nil`), as well as formatting not being great. All of this making it not
something to recommend, and better handled with Go's stdlib.
As far as I could find, there's no external consumers of this, but let's
deprecate first, and remove in the next release.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This command was using a custom "multi-error" implementation, but it
had some limitations, and the formatting wasn't great.
This patch replaces it with Go's errors.Join.
Before:
docker plugin remove one two three
Error response from daemon: plugin "one" not found, Error response from daemon: plugin "two" not found, Error response from daemon: plugin "three" not found
After:
docker plugin remove one two three
Error response from daemon: plugin "one" not found
Error response from daemon: plugin "two" not found
Error response from daemon: plugin "three" not found
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Remove the registerCompletionFuncForGlobalFlags for now, as
the error it returned was ignored, so it didn't add much
benefit, other than abstracting things.
Split the underlying completion-functions to separate
functions, and add some basic tests for them.
Remove the completions helper, as it now didn't add much,
and it saved having the dependency on the package.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Before:
go test -test.coverprofile -
PASS
coverage: 65.2% of statements
ok github.com/docker/cli/templates 0.607s
After:
go test -test.coverprofile -
PASS
coverage: 95.7% of statements
ok github.com/docker/cli/templates 0.259s
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Prevent some tests from failing when running from a pre-compiled
testbinary, and discard output to make the output less noisy.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>