MCPcopy Index your code
hub / github.com/docker/cli / runList

Function runList

cli/command/context/list.go:46–115  ·  view source on GitHub ↗
(dockerCli command.Cli, opts *listOptions)

Source from the content-addressed store, hash-verified

44}
45
46func 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 }

Callers 5

TestListFunction · 0.70
TestListJSONFunction · 0.70
TestListQuietFunction · 0.70
TestListErrorFunction · 0.70
newListCommandFunction · 0.70

Calls 7

formatFunction · 0.85
ListMethod · 0.65
ContextStoreMethod · 0.65
CurrentContextMethod · 0.65
GetMetadataMethod · 0.65
ErrMethod · 0.65
ErrorMethod · 0.45

Tested by 4

TestListFunction · 0.56
TestListJSONFunction · 0.56
TestListQuietFunction · 0.56
TestListErrorFunction · 0.56

Used in the wild real call sites across dependent graphs

searching dependent graphs…