Add WithMessagePrinter to allow callers of DisplayStream and
DisplayMessages to customize presentation of non-auxiliary messages.
The custom printer replaces the default terminal-aware rendering, allowing
callers to handle progress output, terminal sizing, and message errors as
needed. Auxiliary messages continue to use WithAuxCallback.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
These can replace the existing DisplayJSONMessagesStream and DisplayJSONMessages
functions, not requiring the caller to perform terminal detection.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Internalize the `formatStatus` and `formatProgress` methods and consolidate
them into a single `format` method. The different implementations used
different arguments for these, so make those details internal to the
implementation.
Introduce an `emptyMessage` method, which is still used for the JSON formatter
but needs to be looked into.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
- Inline the `formatStatus` function.
- The `formatStatus` methods were never called with a format-string, so we
can remove it.
- Marshaling the `jsonstream.Message` should never produce an error with
the given struct, so remove the `formatError` and return nil (similar
to what's done elsewhere.
- Also do some minor cleanup in `jsonProgressFormatter.formatProgress`
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This test was added in 956c5b61ce, but
wasn't really testing anything (other than testing stdlib).
Ironically there was a review comment on the PR, but about the naming
of the test, and not about the test itself;
> but it isn't really testing NewJSONProgressOutput. NewJSONProgressOutput
> just returns a struct. IMHO it's testing WriteProgress.
Let's make the test test something.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This option was added to handle the deprecated `ProgressMessage` field,
which was removed in fdaccdb233.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Reduce wrapping (Updatef > Update) to make it clearer what functions
are used (or no longer used).
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
The `DisplayJSONMessages` only accepted a `JSONMessagesStream`. This meant that
it would not accept the output from (for example) [client.ImagePushResponse].
This patch:
- Makes `DisplayJSONMessages` accept any `iter.Seq2[jsonstream.Message, error]`
- Makes `JSONMessagesStream` an alias instead of a concrete type (TBD if we
actually need the type).
- Some minor cleanups in the implementation.
[client.ImagePushResponse]: https://github.com/moby/moby/blob/fa87120ae64a170fd42096de3b873b439b95016b/client/image_push.go#L20-L24
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
client/container_exec.go:8:2: import "github.com/containerd/errdefs" imported without alias but must be with alias "cerrdefs" according to config (importas)
"github.com/containerd/errdefs"
^
client/container_exec_test.go:9:2: import "github.com/containerd/errdefs" imported without alias but must be with alias "cerrdefs" according to config (importas)
"github.com/containerd/errdefs"
^
client/container_rename.go:8:2: import "github.com/containerd/errdefs" imported without alias but must be with alias "cerrdefs" according to config (importas)
"github.com/containerd/errdefs"
^
client/pkg/security/security_opts_test.go:8:2: import "gotest.tools/v3/assert/cmp" imported without alias but must be with alias "is" according to config (importas)
"gotest.tools/v3/assert/cmp"
^
client/volume_prune.go:9:2: import "github.com/containerd/errdefs" imported without alias but must be with alias "cerrdefs" according to config (importas)
"github.com/containerd/errdefs"
^
client/volume_prune_test.go:8:2: import "github.com/containerd/errdefs" imported without alias but must be with alias "cerrdefs" according to config (importas)
"github.com/containerd/errdefs"
^
client/container_exec_test.go:10:2: ST1019(related information): other import of "github.com/containerd/errdefs" (staticcheck)
cerrdefs "github.com/containerd/errdefs"
^
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Un-export or remove utilities that have no (external) users;
- AuxFormatter (not used)
- FormatError (only used internally)
- FormatStatus (only used internally)
- NewJSONProgressOutput (used by CLI)
- NewProgressOutput (used by compose, cli for classic builder)
- NewStderrWriter (not used)
- NewStdoutWriter (not used)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This utility is used to split the SecurityOptions field from the
"/info" response into a slice of security.Option. It's effectively
only used by the CLI to present the `docker info` output, but has
a use in buildx to parse the response.
We can assume the daemon returns a valid response, remove the error-
conditions and fallback for legacy daemon versions (< 1.13), and limit
it to parsing the response only.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
The schema of a JSON-stream message is very pertinent to the api module.
Provide a canonical definition in the api module and refactor the daemon
code to use it. Drop the long-deprecated ErrorMessage field from the API
definition, but have the daemon continue to emit it for compatibility
with docker-py v7.1.0.
Co-authored-by: Cory Snider <csnider@mirantis.com>
Signed-off-by: Austin Vazquez <austin.vazquez@docker.com>
Move the progress package up into the client as a temporary shared location for
common clients like CLI and compose.
The progress package is used by the daemon to write progress updates to
some sink, typically a streamformatter. This package is of little use to
API clients as this package does not provide any facilities to consume
the progress updates.
Co-authored-by: Cory Snider <csnider@mirantis.com>
Signed-off-by: Austin Vazquez <austin.vazquez@docker.com>
Move the streamformatter package up into the client for a temporary
shared location between common clients like CLI and compose.
The streamformatter package is used by the daemon to write streams of
status and progress messages to API clients. It is completely out of
scope of the api module and not used outside the daemon. Remove the
unused rawSteamFormatter, whose purpose is to render the progress as a
TUI.
Co-authored-by: Cory Snider <csnider@mirantis.com>
Signed-off-by: Austin Vazquez <austin.vazquez@docker.com>
This change moves the api/types/versions package out into client and daemon versions.
Co-authored-by: Claude <noreply@anthropic.com>
Signed-off-by: Austin Vazquez <austin.vazquez@docker.com>
This change moves the `system.SecurityOpt` type and `system.DecodeSecurityOptions` function to the client and adds a set of unit tests to capture current implementation. This change also create a set of daemon backend copies for usage.
Signed-off-by: Austin Vazquez <austin.vazquez@docker.com>
The JSONMessage struct contained fields that were previously used to produce the
`/events` response. However, commit 72f1881df1
introduced an events.Message type that replaced the use of JSONMessage for
that purpose, and clients no longer use the JSONMessage struct to unmarshal
those responses.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Not perfect yet, but addressing some godoc "doc" links that needed
to be updated, and touching up some references.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
It was an adaptor around DisplayJSONMessagesStream for CLI-specific
primitives that was used in the CLI, but can be implemented by users
of this package.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
The API still returns it for backward-compatibility (but probably
shouldn't), but we should no longer print it. This removes the
use of these fields for printing, but keeps them for streamformatter
to use.
- ErrorMessage was deprecated in 3043c26419
- ProgressMessage was deprecated in 597e0e69b4
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
The stringid package is used in many places; while it's trivial
to implement a similar utility, let's just provide it as a utility
package in the client, removing the daemon-specific logic.
For integration tests, I opted to use the implementation in the
client, as those should not ideally not make assumptions about
the daemon implementation.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>