diff --git a/internal/validate/path.go b/internal/validate/path.go index 6d37206..fb63cee 100644 --- a/internal/validate/path.go +++ b/internal/validate/path.go @@ -1,23 +1,12 @@ package validate import ( - "github.com/rs/zerolog/log" - - "github.com/spf13/afero" + "os" ) -// Path checks if a file at the given path exists and returns it if so, +// PathExists checks if a file at the given path exists and returns it if so, // otherwise returns a default path. -func Path(fs afero.Fs, path string) string { - ok, err := afero.Exists(fs, path) - if err != nil { - log.Fatal().Err(err).Send() - } - - if ok { - return path - } - - log.Fatal().Msg("no valid path provided") - return "." +func PathExists(path string) bool { + _, err := os.Stat(path) + return err == nil } diff --git a/pkg/hunter/config.go b/pkg/hunter/config.go index 51ba13b..0be035e 100644 --- a/pkg/hunter/config.go +++ b/pkg/hunter/config.go @@ -78,7 +78,18 @@ func WithFS(fs afero.Fs) ConfigOption { func WithScanPath(path string) ConfigOption { return func(c *Config) { - c.ScanPath = validate.Path(c.Filesystem, c.ScanPath) + if validate.PathExists(path) { + c.ScanPath = path + return + } + + currentDir, err := os.Getwd() + if err != nil { + log.Fatal().Err(err).Msg("failed to get current dir") + } + + log.Error().Msgf("scan path %q not found, defaulting to %q", path, currentDir) + c.ScanPath = currentDir } }