Skip to content

Commit

Permalink
add fs wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
Tighearnán Carroll committed Mar 27, 2023
1 parent 3e06956 commit 43cbcbe
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
21 changes: 21 additions & 0 deletions internal/storage/fs.go
Original file line number Diff line number Diff line change
@@ -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)
}
6 changes: 2 additions & 4 deletions run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}

0 comments on commit 43cbcbe

Please # to comment.