Files
iris-context/spec/system.go
VERSE ebde9ba68f refactor(commands): separate commands and its core into two folders (#32)
- I think it would be better if one for commands only, one for the spec
handling core logic so people won't be confused by the core logic inside
the commands folder (cleaner I guess)
- Regen docs
2026-07-05 11:27:30 +07:00

39 lines
691 B
Go

package spec
import (
"os"
"path/filepath"
"sync"
)
var (
pathCmds = make(map[string]bool)
pathCmdsOnce sync.Once
)
// scanExternalCommands populates pathCmds with system executables
func scanExternalCommands() {
pathCmdsOnce.Do(func() {
scanPath()
})
}
// scanPath populates pathCmds with all executable files found in path environment variable
func scanPath() {
dirs := filepath.SplitList(os.Getenv("PATH"))
for _, dir := range dirs {
files, err := os.ReadDir(dir)
if err != nil {
continue
}
for _, f := range files {
if !f.IsDir() {
info, err := f.Info()
if err == nil && info.Mode()&0111 != 0 {
pathCmds[f.Name()] = true
}
}
}
}
}