NetworkNames includes {"bridge","host","none"}
(cmd *cobra.Command, exclude []string)
| 106 | |
| 107 | // NetworkNames includes {"bridge","host","none"} |
| 108 | func 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 | |
| 144 | func VolumeNames(cmd *cobra.Command) ([]string, cobra.ShellCompDirective) { |
| 145 | globalOptions, err := helpers.ProcessRootCmdFlags(cmd) |
no test coverage detected
searching dependent graphs…