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
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user