cli/command/context: context ls: add ERROR column, and don't fail early
This updates `docker context ls` to: - not abort listing contexts when failing one (or more) contexts - instead, adding an ERROR column to inform the user there was an issue loading the context. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
@ -56,17 +56,26 @@ func runList(dockerCli command.Cli, opts *listOptions) error {
|
||||
isCurrent := rawMeta.Name == curContext
|
||||
meta, err := command.GetDockerContext(rawMeta)
|
||||
if err != nil {
|
||||
return err
|
||||
// Add a stub-entry to the list, including the error-message
|
||||
// indicating that the context couldn't be loaded.
|
||||
contexts = append(contexts, &formatter.ClientContext{
|
||||
Name: rawMeta.Name,
|
||||
Current: isCurrent,
|
||||
Error: err.Error(),
|
||||
})
|
||||
continue
|
||||
}
|
||||
var errMsg string
|
||||
dockerEndpoint, err := docker.EndpointFromContext(rawMeta)
|
||||
if err != nil {
|
||||
return err
|
||||
errMsg = err.Error()
|
||||
}
|
||||
desc := formatter.ClientContext{
|
||||
Name: rawMeta.Name,
|
||||
Current: isCurrent,
|
||||
Description: meta.Description,
|
||||
DockerEndpoint: dockerEndpoint.Host,
|
||||
Error: errMsg,
|
||||
}
|
||||
contexts = append(contexts, &desc)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user