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

Method query

cmds/cmd_reverse.go:81–126  ·  view source on GitHub ↗
(target string)

Source from the content-addressed store, hash-verified

79}
80
81func (r *reverseCmd) query(target string) ([]string, error) {
82 var libraries []string
83 visited := map[string]bool{}
84
85 walkPorts := func(root string) error {
86 return filepath.WalkDir(root, func(path string, d fs.DirEntry, err error) error {
87 if err != nil {
88 return nil
89 }
90 if d.IsDir() && strings.HasPrefix(d.Name(), ".") {
91 return filepath.SkipDir
92 }
93 if d.IsDir() || d.Name() != "port.toml" {
94 return nil
95 }
96
97 portDir := filepath.Dir(path)
98 libVersion := filepath.Base(portDir)
99 libName := filepath.Base(filepath.Dir(portDir))
100 nameVersion := libName + "@" + libVersion
101
102 if visited[nameVersion] {
103 return nil
104 }
105 visited[nameVersion] = true
106
107 if r.tomlHasDependency(path, target) {
108 libraries = append(libraries, nameVersion)
109 }
110 return nil
111 })
112 }
113
114 if fileio.PathExists(dirs.PortsDir) {
115 walkPorts(dirs.PortsDir)
116 }
117 if r.celer.Project().GetName() != "" {
118 projectDir := filepath.Join(dirs.ConfProjectsDir, r.celer.Project().GetName())
119 if fileio.PathExists(projectDir) {
120 walkPorts(projectDir)
121 }
122 }
123
124 sort.Strings(libraries)
125 return libraries, nil
126}
127
128// tomlDeps is a minimal struct for extracting dependencies from port.toml
129// without the overhead of a full Port.Init().

Callers 4

doExecuteMethod · 0.95
TestReverseCmd_With_DevFunction · 0.95

Calls 5

tomlHasDependencyMethod · 0.95
PathExistsFunction · 0.92
NameMethod · 0.65
GetNameMethod · 0.65
ProjectMethod · 0.65

Tested by 3

TestReverseCmd_With_DevFunction · 0.76