spf13 / viper

Go configuration with fangs
MIT License
26.29k stars 2.01k forks source link

Replace file searching API with a finder #1795

Closed sagikazarmark closed 1 month ago

sagikazarmark commented 3 months ago

Preflight Checklist

Problem Description

The current API for file searching is extremely confusing, hard to explain and is full of edge cases that people rely on and then open issues/PRs with "fixes" when they break.

Examples:

The current implementation is also not very extensible (people can't workaround issues).

Proposed Solution

Deprecate the current API (SetConfigName, AddConfigPath) and replace it with a Finder interface:

type Finder interface {
    Find(fsys afero.FS) ([]string, error)
}

Finder should return a list of file paths that match a certain search criteria in the specific filesystem. (Viper uses afero as a filesystem abstraction under the hood. I don't see that going away in the short run, ie. we can't easily replace it with io/fs, so I believe it's safe to use it in the new interface)

How that search criteria is applied is up to the implementation which allows users to extend the file search implementation.

The reference implementation for Finder is locafero. To remain backwards compatible on the v1 branch we can use locafero under the hood.

Alternatives Considered

No response

Additional Information

No response