mirror of https://github.com/docker/cli.git
cli/command/context: "docker context show": don't validate context
The "docker context show" command is intended to show the currently configured context. While the context that's configured may not be valid (e.g., in case an environment variable was set to configure the context, or if the context was removed from the filesystem), we should still be able to _show_ the context. This patch removes the context validation, and instead only shows the context. 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>
This commit is contained in:
parent
cbf052252b
commit
6ba7de3b5a
|
@ -16,19 +16,14 @@ func newShowCommand(dockerCli command.Cli) *cobra.Command {
|
||||||
Short: "Print the name of the current context",
|
Short: "Print the name of the current context",
|
||||||
Args: cli.NoArgs,
|
Args: cli.NoArgs,
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
return runShow(dockerCli)
|
runShow(dockerCli)
|
||||||
|
return nil
|
||||||
},
|
},
|
||||||
ValidArgsFunction: completion.NoComplete,
|
ValidArgsFunction: completion.NoComplete,
|
||||||
}
|
}
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
func runShow(dockerCli command.Cli) error {
|
func runShow(dockerCli command.Cli) {
|
||||||
context := dockerCli.CurrentContext()
|
fmt.Fprintln(dockerCli.Out(), dockerCli.CurrentContext())
|
||||||
metadata, err := dockerCli.ContextStore().GetMetadata(context)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
fmt.Fprintln(dockerCli.Out(), metadata.Name)
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,6 @@ package context
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"gotest.tools/v3/assert"
|
|
||||||
"gotest.tools/v3/golden"
|
"gotest.tools/v3/golden"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -13,6 +12,6 @@ func TestShow(t *testing.T) {
|
||||||
cli.SetCurrentContext("current")
|
cli.SetCurrentContext("current")
|
||||||
|
|
||||||
cli.OutBuffer().Reset()
|
cli.OutBuffer().Reset()
|
||||||
assert.NilError(t, runShow(cli))
|
runShow(cli)
|
||||||
golden.Assert(t, cli.OutBuffer().String(), "show.golden")
|
golden.Assert(t, cli.OutBuffer().String(), "show.golden")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue