3 Commits

Author SHA1 Message Date
af0a9f9c4c docs: Added todos. 2025-11-05 18:31:39 -05:00
4273fa5895 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
2025-11-05 18:29:19 -05:00
bb3c0cdeee chore: Updated nix version. 2025-11-05 18:09:58 -05:00
2 changed files with 65 additions and 57 deletions

View File

@@ -24,9 +24,11 @@ type SshKeyPair struct {
} }
type scanConfig struct { type scanConfig struct {
// TODO: Support multiple matchers
Matcher string `json:"matcher"` Matcher string `json:"matcher"`
// TODO: Support multiple excludes
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 +49,7 @@ func NewConfig(privateKeyPaths []string) Config {
ScanConfig: scanConfig{ ScanConfig: scanConfig{
Matcher: "\\.env", Matcher: "\\.env",
Exclude: "*.envrc", Exclude: "*.envrc",
Include: "~", Include: []string{"~"},
}, },
} }
} }
@@ -109,17 +111,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 +157,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?

View File

@@ -61,7 +61,7 @@
packages.default = pkgs.buildGoModule rec { packages.default = pkgs.buildGoModule rec {
pname = "envr"; pname = "envr";
version = "0.1.0"; version = "0.1.1";
src = ./.; src = ./.;
# If the build complains, uncomment this line # If the build complains, uncomment this line
# vendorHash = "sha256:0000000000000000000000000000000000000000000000000000"; # vendorHash = "sha256:0000000000000000000000000000000000000000000000000000";