DockerCLI/cli/command
Sebastiaan van Stijn bca2090061
cli: make cli.StatusError slightly prettier
This error didn't do a great job at formatting. If a StatusError was
produced without a Status message, it would print a very non-informative
error, with information missing.

Let's update the output:

- If a status-message is provided; print just that (after all the
  status code is something that can be found from the shell, e.g.
  through `echo $?` in Bash).
- If no status-message is provided: print a message more similar to
  Go's `exec.ExecError`, which uses `os.rocessState.String()` (see [1]).

Before this patch, an error without custom status would print:

    Status: , Code: 2

After this patch:

    exit status 2

In situations where a custom error-message is provided, the error-message
is print as-is, whereas before this patch, the message got combined with
the `Status:` and `Code:`, which resulted in some odd output.

Before this patch:

    docker volume --no-such-flag
    Status: unknown flag: --no-such-flag
    See 'docker volume --help'.

    Usage:  docker volume COMMAND

    Manage volumes

    Commands:
      create      Create a volume
      inspect     Display detailed information on one or more volumes
      ls          List volumes
      prune       Remove unused local volumes
      rm          Remove one or more volumes
      update      Update a volume (cluster volumes only)

    Run 'docker volume COMMAND --help' for more information on a command.
    , Code: 125

With this patch, the error is shown as-is;

    docker volume --no-such-flag
    unknown flag: --no-such-flag
    See 'docker volume --help'.

    Usage:  docker volume COMMAND

    Manage volumes

    Commands:
      create      Create a volume
      inspect     Display detailed information on one or more volumes
      ls          List volumes
      prune       Remove unused local volumes
      rm          Remove one or more volumes
      update      Update a volume (cluster volumes only)

    Run 'docker volume COMMAND --help' for more information on a command.

While the exit-code is no longer printed, it's still properly handled;

    echo $?
    125

[1]: 82c14346d8/src/os/exec_posix.go (L107-L135)

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-07-04 22:08:18 +02:00
..
builder test spring-cleaning 2024-07-04 01:35:12 +02:00
checkpoint test spring-cleaning 2024-07-04 01:35:12 +02:00
commands remove exec, push, pull, ps, images, info from "legacy" commands 2022-04-08 16:55:39 +02:00
completion replace uses of deprecated API types 2024-07-04 15:22:18 +02:00
config test spring-cleaning 2024-07-04 01:35:12 +02:00
container replace uses of deprecated API types 2024-07-04 15:22:18 +02:00
context Update go:build comments to go1.21 2024-06-18 12:17:13 +02:00
formatter replace uses of deprecated API types 2024-07-04 15:22:18 +02:00
idresolver Update go:build comments to go1.21 2024-06-18 12:17:13 +02:00
image replace uses of deprecated API types 2024-07-04 15:22:18 +02:00
inspect Update go:build comments to go1.21 2024-06-18 12:17:13 +02:00
manifest test spring-cleaning 2024-07-04 01:35:12 +02:00
network cli: make cli.StatusError slightly prettier 2024-07-04 22:08:18 +02:00
node test spring-cleaning 2024-07-04 01:35:12 +02:00
plugin test spring-cleaning 2024-07-04 01:35:12 +02:00
registry fix: ctx cancellation on login prompt 2024-07-02 12:07:16 +02:00
secret test spring-cleaning 2024-07-04 01:35:12 +02:00
service test spring-cleaning 2024-07-04 01:35:12 +02:00
stack test spring-cleaning 2024-07-04 01:35:12 +02:00
swarm test spring-cleaning 2024-07-04 01:35:12 +02:00
system cli: make cli.StatusError slightly prettier 2024-07-04 22:08:18 +02:00
task linting: address slice-append issues found by gocritic 2023-11-20 16:02:17 +01:00
testdata Dynamically register kubernetes context store endpoint type. 2019-05-20 13:28:11 +01:00
trust replace uses of deprecated API types 2024-07-04 15:22:18 +02:00
volume test spring-cleaning 2024-07-04 01:35:12 +02:00
cli.go cli: make initializing the global meter- and tracing providers optional 2024-06-24 15:44:20 +02:00
cli_options.go cli: Wrap Err stream 2024-06-11 17:59:48 +02:00
cli_options_test.go golangci-lint: enable thelper linter 2023-11-20 16:02:17 +01:00
cli_test.go cli: Wrap Err stream 2024-06-11 17:59:48 +02:00
context.go Update go:build comments to go1.21 2024-06-18 12:17:13 +02:00
context_test.go Update go:build comments to go1.21 2024-06-18 12:17:13 +02:00
defaultcontextstore.go Update go:build comments to go1.21 2024-06-18 12:17:13 +02:00
defaultcontextstore_test.go Update go:build comments to go1.21 2024-06-18 12:17:13 +02:00
registry.go fix: ctx cancellation on login prompt 2024-07-02 12:07:16 +02:00
registry_test.go linting: fmt.Sprintf can be replaced with string concatenation (perfsprint) 2024-06-10 21:19:32 +02:00
telemetry.go OTel: implement missing MeterProvider `ForceFlush` 2024-05-15 00:05:31 +01:00
telemetry_docker.go Update go:build comments to go1.21 2024-06-18 12:17:13 +02:00
telemetry_options.go cli: make initializing the global meter- and tracing providers optional 2024-06-24 15:44:20 +02:00
telemetry_utils.go cli: Wrap Err stream 2024-06-11 17:59:48 +02:00
telemetry_utils_test.go cli: Wrap Err stream 2024-06-11 17:59:48 +02:00
trust.go Refactor content_trust cli/flags handling 2018-03-08 15:00:43 -05:00
utils.go fix: ctx cancellation on login prompt 2024-07-02 12:07:16 +02:00
utils_test.go fix: ctx cancellation on login prompt 2024-07-02 12:07:16 +02:00