Skip to content

Commit fb887a5

Browse files
committed
fix: extendedVars
1 parent 861b20d commit fb887a5

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

docs/helpers/extendedEnv.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,23 @@ func GetRogueEnvs() {
6868
if err := os.Chdir("../../"); err != nil {
6969
log.Fatal(err)
7070
}
71-
fmt.Println("Gathering variable definitions from source")
72-
out, err := exec.Command("sh", "-c", "grep -RHn os.Getenv --exclude-dir=vendor | grep -v extendedEnv.go |grep \\.go").Output()
71+
72+
// Option to process a specific directory, for faster development iteration
73+
processDir := os.Getenv("DIR")
74+
if processDir == "" {
75+
processDir = "."
76+
}
77+
78+
fmt.Printf("Processing directory: %s\n", processDir)
79+
80+
// Old command `grep -RHn os.Getenv $DIR --exclude-dir=vendor | grep -v extendedEnv.go | grep \\.go`
81+
// New command, 10x faster than direct grep:
82+
// C_ALL=C - Sets locale to C for consistent output
83+
// find %s -type f -name '*.go' - Finds all .go files in the specified directory
84+
// xargs -0 -P $(getconf _NPROCESSORS_ONLN) - Processes files in parallel using all available CPU cores
85+
// grep -F -Hn 'os.Getenv' - Searches for literal "os.Getenv" with filename and line number output
86+
grepCmd := fmt.Sprintf("C_ALL=C find %s -type f -name '*.go' -not -path '*/vendor/*' -print0 | xargs -0 -P $(getconf _NPROCESSORS_ONLN) grep -F -Hn 'os.Getenv' | grep -v extendedEnv.go", processDir)
87+
out, err := exec.Command("sh", "-c", grepCmd).Output()
7388
if err != nil {
7489
log.Fatal(err)
7590
}

0 commit comments

Comments
 (0)