diff --git a/internal/flags/options.go b/internal/flags/options.go index bbb38112..fed059a7 100644 --- a/internal/flags/options.go +++ b/internal/flags/options.go @@ -72,7 +72,7 @@ type Options struct { FeatureContents []Feature // FS allows passing in an `fs.FS` to read features from, such as an `embed.FS` - // or os.DirFS(string). Defaults to os.DirFS("./"). + // or os.DirFS(string). FS fs.FS // ShowHelp enables suite to show CLI flags usage help and exit. diff --git a/internal/storage/fs.go b/internal/storage/fs.go new file mode 100644 index 00000000..333c61de --- /dev/null +++ b/internal/storage/fs.go @@ -0,0 +1,21 @@ +package storage + +import ( + "io/fs" + "os" +) + +// FS is a wrapper that falls back to `os`. +type FS struct { + FS fs.FS +} + +// Open a file in the provided `fs.FS`. If none provided, +// open via `os.Open` +func (f FS) Open(name string) (fs.File, error) { + if f.FS == nil { + return os.Open(name) + } + + return f.FS.Open(name) +} diff --git a/run.go b/run.go index c1cec502..02479e63 100644 --- a/run.go +++ b/run.go @@ -226,9 +226,7 @@ func runWithOptions(suiteName string, runner runner, opt Options) int { } runner.fmt = multiFmt.FormatterFunc(suiteName, output) - if opt.FS == nil { - opt.FS = os.DirFS("./") - } + opt.FS = storage.FS{FS: opt.FS} if len(opt.FeatureContents) > 0 { features, err := parser.ParseFromBytes(opt.Tags, opt.FeatureContents) @@ -372,7 +370,7 @@ func getDefaultOptions() (*Options, error) { } opt.Paths = flagSet.Args() - opt.FS = os.DirFS("./") + opt.FS = storage.FS{FS: os.DirFS("./")} return opt, nil }