docker version: add "context" to output
This adds the currently selected "docker context" to the output
of "docker version", which allows users to see which context
is selected to produce the version output, and can be used (for
example), to set the prompt to the currently selected context:
(in `~/.bashrc`):
```bash
function docker_context_prompt() {
PS1="context: $(docker version --format='{{.Client.Context}}')> "
}
PROMPT_COMMAND=docker_context_prompt
```
After reloading the `~/.bashrc`, the prompt now shows the currently selected
`docker context`:
```bash
$ source ~/.bashrc
context: default> docker context create --docker host=unix:///var/run/docker.sock my-context
my-context
Successfully created context "my-context"
context: default> docker context use my-context
my-context
Current context is now "my-context"
context: my-context> docker context use default
default
Current context is now "default"
context: default>
```
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
@ -5,6 +5,7 @@ Client:
|
||||
Git commit: deadbeef
|
||||
Built: Wed May 30 22:21:05 2018
|
||||
OS/Arch: linux/amd64
|
||||
Context: my-context
|
||||
Experimental: true
|
||||
|
||||
Server: Docker Enterprise Edition (EE) 2.0
|
||||
|
||||
@ -32,6 +32,7 @@ Client:{{if ne .Platform.Name ""}} {{.Platform.Name}}{{end}}
|
||||
Git commit: {{.GitCommit}}
|
||||
Built: {{.BuildTime}}
|
||||
OS/Arch: {{.Os}}/{{.Arch}}
|
||||
Context: {{.Context}}
|
||||
Experimental: {{.Experimental}}
|
||||
{{- end}}
|
||||
|
||||
@ -80,6 +81,7 @@ type clientVersion struct {
|
||||
Os string
|
||||
Arch string
|
||||
BuildTime string `json:",omitempty"`
|
||||
Context string
|
||||
Experimental bool
|
||||
}
|
||||
|
||||
@ -147,6 +149,7 @@ func runVersion(dockerCli command.Cli, opts *versionOptions) error {
|
||||
Os: runtime.GOOS,
|
||||
Arch: runtime.GOARCH,
|
||||
Experimental: dockerCli.ClientInfo().HasExperimental,
|
||||
Context: dockerCli.CurrentContext(),
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@ -41,6 +41,7 @@ func TestVersionAlign(t *testing.T) {
|
||||
Os: "linux",
|
||||
Arch: "amd64",
|
||||
BuildTime: "Wed May 30 22:21:05 2018",
|
||||
Context: "my-context",
|
||||
Experimental: true,
|
||||
},
|
||||
Server: &types.Version{},
|
||||
|
||||
Reference in New Issue
Block a user