feat!: Multiple scan includes are now supported.

BREAKING CHANGE: The config value `scan.Include` is now a list rather than
a string.

Release-As: 0.2.0
This commit is contained in:
2025-11-05 18:23:43 -05:00
parent bb3c0cdeee
commit 4273fa5895

View File

@@ -26,7 +26,7 @@ type SshKeyPair struct {
type scanConfig struct { type scanConfig struct {
Matcher string `json:"matcher"` Matcher string `json:"matcher"`
Exclude string `json:"exclude"` Exclude string `json:"exclude"`
Include string `json:"include"` Include []string `json:"include"`
} }
// Create a fresh config with sensible defaults. // Create a fresh config with sensible defaults.
@@ -47,7 +47,7 @@ func NewConfig(privateKeyPaths []string) Config {
ScanConfig: scanConfig{ ScanConfig: scanConfig{
Matcher: "\\.env", Matcher: "\\.env",
Exclude: "*.envrc", Exclude: "*.envrc",
Include: "~", Include: []string{"~"},
}, },
} }
} }
@@ -109,17 +109,18 @@ func (c *Config) Save() error {
// Use fd to find all ignored .env files that match the config's parameters // Use fd to find all ignored .env files that match the config's parameters
func (c Config) scan() (paths []string, err error) { func (c Config) scan() (paths []string, err error) {
searchPath, err := c.searchPath() searchPaths, err := c.searchPaths()
if err != nil { if err != nil {
return []string{}, err return []string{}, err
} }
for _, searchPath := range searchPaths {
// Find all files (including ignored ones) // Find all files (including ignored ones)
fmt.Printf("Searching for all files in \"%s\"...\n", searchPath) fmt.Printf("Searching for all files in \"%s\"...\n", searchPath)
allCmd := exec.Command("fd", "-a", c.ScanConfig.Matcher, "-E", c.ScanConfig.Exclude, "-HI", searchPath) allCmd := exec.Command("fd", "-a", c.ScanConfig.Matcher, "-E", c.ScanConfig.Exclude, "-HI", searchPath)
allOutput, err := allCmd.Output() allOutput, err := allCmd.Output()
if err != nil { if err != nil {
return []string{}, err return paths, err
} }
allFiles := strings.Split(strings.TrimSpace(string(allOutput)), "\n") allFiles := strings.Split(strings.TrimSpace(string(allOutput)), "\n")
@@ -154,26 +155,31 @@ func (c Config) scan() (paths []string, err error) {
} }
} }
return ignoredFiles, nil paths = append(paths, ignoredFiles...)
} }
func (c Config) searchPath() (path string, err error) { return paths, nil
include := c.ScanConfig.Include }
if include == "~" { func (c Config) searchPaths() (paths []string, err error) {
homeDir, err := os.UserHomeDir() homeDir, err := os.UserHomeDir()
if err != nil { if err != nil {
return "", err return paths, err
}
return homeDir, nil
} }
absPath, err := filepath.Abs(include) includes := c.ScanConfig.Include
for _, include := range includes {
path := strings.Replace(include, "~", homeDir, 1)
absPath, err := filepath.Abs(path)
if err != nil { if err != nil {
return "", err return paths, err
} }
return absPath, nil paths = append(paths, absPath)
}
return paths, nil
} }
// TODO: Should this be private? // TODO: Should this be private?