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

Function ContainerNames

cmd/nerdctl/completion/completion.go:59–105  ·  view source on GitHub ↗
(cmd *cobra.Command, filterFunc func(containerd.ProcessStatus) bool)

Source from the content-addressed store, hash-verified

57}
58
59func ContainerNames(cmd *cobra.Command, filterFunc func(containerd.ProcessStatus) bool) ([]string, cobra.ShellCompDirective) {
60 globalOptions, err := helpers.ProcessRootCmdFlags(cmd)
61 if err != nil {
62 return nil, cobra.ShellCompDirectiveError
63 }
64 client, ctx, cancel, err := clientutil.NewClient(cmd.Context(), globalOptions.Namespace, globalOptions.Address)
65 if err != nil {
66 return nil, cobra.ShellCompDirectiveError
67 }
68 defer cancel()
69 containers, err := client.Containers(ctx)
70 if err != nil {
71 return nil, cobra.ShellCompDirectiveError
72 }
73 getStatus := func(c containerd.Container) containerd.ProcessStatus {
74 ctx2, cancel2 := context.WithTimeout(ctx, 100*time.Millisecond)
75 defer cancel2()
76 task, err := c.Task(ctx2, nil)
77 if err != nil {
78 return containerd.Unknown
79 }
80 st, err := task.Status(ctx2)
81 if err != nil {
82 return containerd.Unknown
83 }
84 return st.Status
85 }
86 candidates := []string{}
87 for _, c := range containers {
88 if filterFunc != nil {
89 if !filterFunc(getStatus(c)) {
90 continue
91 }
92 }
93 lab, err := c.Labels(ctx)
94 if err != nil {
95 continue
96 }
97 name := lab[labels.Name]
98 if name != "" {
99 candidates = append(candidates, name)
100 continue
101 }
102 candidates = append(candidates, c.ID())
103 }
104 return candidates, cobra.ShellCompDirectiveNoFileComp
105}
106
107// NetworkNames includes {"bridge","host","none"}
108func NetworkNames(cmd *cobra.Command, exclude []string) ([]string, cobra.ShellCompDirective) {

Callers 15

portShellCompleteFunction · 0.92
renameShellCompleteFunction · 0.92
statsShellCompleteFunction · 0.92
killShellCompleteFunction · 0.92
diffShellCompleteFunction · 0.92
stopShellCompleteFunction · 0.92
pauseShellCompleteFunction · 0.92
execShellCompleteFunction · 0.92
startShellCompleteFunction · 0.92
logsShellCompleteFunction · 0.92
unpauseShellCompleteFunction · 0.92

Calls 5

ProcessRootCmdFlagsFunction · 0.92
NewClientFunction · 0.92
ContainersMethod · 0.80
WithTimeoutMethod · 0.65
LabelsMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…