(dockerCli command.Cli, opts *listOptions)
| 44 | } |
| 45 | |
| 46 | func runList(dockerCli command.Cli, opts *listOptions) error { |
| 47 | if opts.format == "" { |
| 48 | opts.format = formatter.TableFormatKey |
| 49 | } |
| 50 | contextMap, err := dockerCli.ContextStore().List() |
| 51 | if err != nil { |
| 52 | return err |
| 53 | } |
| 54 | var ( |
| 55 | curContext = dockerCli.CurrentContext() |
| 56 | curFound bool |
| 57 | contexts = make([]*formatter.ClientContext, 0, len(contextMap)) |
| 58 | ) |
| 59 | for _, rawMeta := range contextMap { |
| 60 | isCurrent := rawMeta.Name == curContext |
| 61 | if isCurrent { |
| 62 | curFound = true |
| 63 | } |
| 64 | meta, err := command.GetDockerContext(rawMeta) |
| 65 | if err != nil { |
| 66 | // Add a stub-entry to the list, including the error-message |
| 67 | // indicating that the context couldn't be loaded. |
| 68 | contexts = append(contexts, &formatter.ClientContext{ |
| 69 | Name: rawMeta.Name, |
| 70 | Current: isCurrent, |
| 71 | Error: err.Error(), |
| 72 | }) |
| 73 | continue |
| 74 | } |
| 75 | var errMsg string |
| 76 | dockerEndpoint, err := docker.EndpointFromContext(rawMeta) |
| 77 | if err != nil { |
| 78 | errMsg = err.Error() |
| 79 | } |
| 80 | desc := formatter.ClientContext{ |
| 81 | Name: rawMeta.Name, |
| 82 | Current: isCurrent, |
| 83 | Description: meta.Description, |
| 84 | DockerEndpoint: dockerEndpoint.Host, |
| 85 | Error: errMsg, |
| 86 | } |
| 87 | contexts = append(contexts, &desc) |
| 88 | } |
| 89 | if !curFound { |
| 90 | // The currently specified context wasn't found. We add a stub-entry |
| 91 | // to the list, including the error-message indicating that the context |
| 92 | // wasn't found. |
| 93 | var errMsg string |
| 94 | _, err := dockerCli.ContextStore().GetMetadata(curContext) |
| 95 | if err != nil { |
| 96 | errMsg = err.Error() |
| 97 | } |
| 98 | contexts = append(contexts, &formatter.ClientContext{ |
| 99 | Name: curContext, |
| 100 | Current: true, |
| 101 | Error: errMsg, |
| 102 | }) |
| 103 | } |
searching dependent graphs…