| 79 | } |
| 80 | |
| 81 | func (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(). |