MCPcopy Create free account
hub / github.com/celer-pkg/celer / completion

Method completion

cmds/cmd_reverse.go:166–210  ·  view source on GitHub ↗
(cmd *cobra.Command, args []string, toComplete string)

Source from the content-addressed store, hash-verified

164}
165
166func (r *reverseCmd) completion(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
167 suggestions := make([]string, 0)
168 visited := map[string]bool{}
169
170 walkPorts := func(root string) {
171 filepath.WalkDir(root, func(path string, d fs.DirEntry, err error) error {
172 if err != nil {
173 return nil
174 }
175 if d.IsDir() && strings.HasPrefix(d.Name(), ".") {
176 return filepath.SkipDir
177 }
178 if d.IsDir() || d.Name() != "port.toml" {
179 return nil
180 }
181 portDir := filepath.Dir(path)
182 libVersion := filepath.Base(portDir)
183 libName := filepath.Base(filepath.Dir(portDir))
184 nameVersion := libName + "@" + libVersion
185 if !visited[nameVersion] && strings.HasPrefix(nameVersion, toComplete) {
186 visited[nameVersion] = true
187 suggestions = append(suggestions, nameVersion)
188 }
189 return nil
190 })
191 }
192
193 if fileio.PathExists(dirs.PortsDir) {
194 walkPorts(dirs.PortsDir)
195 }
196 if r.celer != nil && r.celer.Project().GetName() != "" {
197 projectDir := filepath.Join(dirs.ConfProjectsDir, r.celer.Project().GetName())
198 if fileio.PathExists(projectDir) {
199 walkPorts(projectDir)
200 }
201 }
202
203 for _, flag := range []string{"--dev", "-d"} {
204 if strings.HasPrefix(flag, toComplete) {
205 suggestions = append(suggestions, flag)
206 }
207 }
208
209 return suggestions, cobra.ShellCompDirectiveNoFileComp
210}
211
212// validatePackageName validates the package name format (name@version)
213func (r *reverseCmd) validatePackageName(packageName string) error {

Callers 1

Calls 4

PathExistsFunction · 0.92
NameMethod · 0.65
GetNameMethod · 0.65
ProjectMethod · 0.65

Tested by 1