MCPcopy Index your code
hub / github.com/nikivdev/go / collectShellScripts

Function collectShellScripts

cli/flow/main.go:2222–2279  ·  view source on GitHub ↗
(root string)

Source from the content-addressed store, hash-verified

2220}
2221
2222func collectShellScripts(root string) ([]scriptCandidate, error) {
2223 info, err := os.Stat(root)
2224 if err != nil {
2225 if errors.Is(err, os.ErrNotExist) {
2226 return nil, fmt.Errorf("scripts directory %s not found", root)
2227 }
2228 return nil, fmt.Errorf("stat %s: %w", root, err)
2229 }
2230 if !info.IsDir() {
2231 return nil, fmt.Errorf("%s is not a directory", root)
2232 }
2233
2234 var scripts []scriptCandidate
2235 err = filepath.WalkDir(root, func(path string, d fs.DirEntry, walkErr error) error {
2236 if walkErr != nil {
2237 if errors.Is(walkErr, fs.ErrPermission) {
2238 return nil
2239 }
2240 return walkErr
2241 }
2242
2243 if d.IsDir() {
2244 return nil
2245 }
2246
2247 entryInfo, err := d.Info()
2248 if err != nil {
2249 return err
2250 }
2251 if !entryInfo.Mode().IsRegular() {
2252 return nil
2253 }
2254
2255 if !isShellScriptFile(d.Name(), entryInfo.Mode()) {
2256 return nil
2257 }
2258
2259 rel, err := filepath.Rel(root, path)
2260 if err != nil {
2261 rel = path
2262 }
2263
2264 scripts = append(scripts, scriptCandidate{
2265 Absolute: path,
2266 Relative: rel,
2267 })
2268 return nil
2269 })
2270 if err != nil {
2271 return nil, err
2272 }
2273
2274 sort.Slice(scripts, func(i, j int) bool {
2275 return scripts[i].Relative < scripts[j].Relative
2276 })
2277
2278 return scripts, nil
2279}

Callers 1

runShExecFunction · 0.85

Calls 1

isShellScriptFileFunction · 0.85

Tested by

no test coverage detected