mukan-ignite/ignite/pkg/localfs/search.go
Mukan Erkin Törük 26b204bd04
Some checks are pending
Docs Deploy / build_and_deploy (push) Waiting to run
Generate Docs / cli (push) Waiting to run
Generate Config Doc / cli (push) Waiting to run
Go formatting / go-formatting (push) Waiting to run
Check links / markdown-link-check (push) Waiting to run
Integration / pre-test (push) Waiting to run
Integration / test on (push) Blocked by required conditions
Integration / status (push) Blocked by required conditions
Lint / Lint Go code (push) Waiting to run
Test / test (ubuntu-latest) (push) Waiting to run
feat: fork Ignite CLI v29 as Mukan Ignite — remove cosmos-sdk restrictions
2026-05-11 03:31:37 +03:00

46 lines
939 B
Go

package localfs
import (
"os"
"path/filepath"
"sort"
"strings"
)
// Search searches for files in the fs with given glob pattern by ensuring that
// returned file paths are sorted.
func Search(path, pattern string) ([]string, error) {
files := make([]string, 0)
if _, err := os.Stat(path); err != nil {
if os.IsNotExist(err) {
return files, nil
}
return nil, err
}
err := filepath.Walk(path, func(path string, f os.FileInfo, err error) error {
if err != nil {
return err
}
base := filepath.Base(path)
// skip hidden folders
if f.IsDir() && strings.HasPrefix(base, ".") {
return filepath.SkipDir
}
// avoid check directories
if f.IsDir() {
return nil
}
// check if the file name and pattern matches
matched, err := filepath.Match(pattern, base)
if err != nil {
return err
}
if matched {
files = append(files, path)
}
return nil
})
sort.Strings(files)
return files, err
}