MCPcopy Create free account
hub / github.com/containerd/nerdctl / NetworkNames

Function NetworkNames

cmd/nerdctl/completion/completion.go:108–142  ·  view source on GitHub ↗

NetworkNames includes {"bridge","host","none"}

(cmd *cobra.Command, exclude []string)

Source from the content-addressed store, hash-verified

106
107// NetworkNames includes {"bridge","host","none"}
108func NetworkNames(cmd *cobra.Command, exclude []string) ([]string, cobra.ShellCompDirective) {
109 globalOptions, err := helpers.ProcessRootCmdFlags(cmd)
110 if err != nil {
111 return nil, cobra.ShellCompDirectiveError
112 }
113 excludeMap := make(map[string]struct{}, len(exclude))
114 for _, ex := range exclude {
115 excludeMap[ex] = struct{}{}
116 }
117
118 e, err := netutil.NewCNIEnv(globalOptions.CNIPath, globalOptions.CNINetConfPath, netutil.WithNamespace(globalOptions.Namespace))
119 if err != nil {
120 return nil, cobra.ShellCompDirectiveError
121 }
122 candidates := []string{}
123 netConfigs, err := e.NetworkMap()
124 if err != nil {
125 return nil, cobra.ShellCompDirectiveError
126 }
127 for netName, network := range netConfigs {
128 if _, ok := excludeMap[netName]; !ok {
129 candidates = append(candidates, netName)
130 if network.NerdctlID != nil {
131 candidates = append(candidates, *network.NerdctlID)
132 candidates = append(candidates, (*network.NerdctlID)[0:12])
133 }
134 }
135 }
136 for _, s := range []string{"host", "none"} {
137 if _, ok := excludeMap[s]; !ok {
138 candidates = append(candidates, s)
139 }
140 }
141 return candidates, cobra.ShellCompDirectiveNoFileComp
142}
143
144func VolumeNames(cmd *cobra.Command) ([]string, cobra.ShellCompDirective) {
145 globalOptions, err := helpers.ProcessRootCmdFlags(cmd)

Callers 3

setCreateFlagsFunction · 0.92
networkRmShellCompleteFunction · 0.92

Calls 4

NetworkMapMethod · 0.95
ProcessRootCmdFlagsFunction · 0.92
NewCNIEnvFunction · 0.92
WithNamespaceFunction · 0.92

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…