Skip to content

Commit 685449f

Browse files
committed
cli/command/context: allow context show to print context, even on error
This allows the user to still see what context is _set_ in cases where it does not exist; docker context show nosuchcontext load context "nosuchcontext": context does not exist: open /root/.docker/contexts/meta/8bfef2a74c7d06add4bf4c73b0af97d9f79c76fe151ae0e18b9d7e57104c149b/meta.json: no such file or directory The error is printed on stderr, so can be redirected: docker context show 2> /dev/null nosuchcontext echo $? 1 This can help in cases where the context is used to (e.g.) set the command-prompt, but the user removed the context. With this change, the context name can still be shown, but commands that _require_ the context will still fail. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent 96e97de commit 685449f

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

cli/command/context/show.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ func newShowCommand(dockerCli command.Cli) *cobra.Command {
2525

2626
func runShow(dockerCli command.Cli) error {
2727
context := dockerCli.CurrentContext()
28-
metadata, err := dockerCli.ContextStore().GetMetadata(context)
28+
fmt.Fprintln(dockerCli.Out(), context)
29+
_, err := dockerCli.ContextStore().GetMetadata(context)
2930
if err != nil {
3031
return err
3132
}
32-
fmt.Fprintln(dockerCli.Out(), metadata.Name)
3333
return nil
3434
}

0 commit comments

Comments
 (0)