@@ -20,7 +20,25 @@ var actionsSubdir = strings.Join([]string{"", actionsDirname, ""}, string(filepa
2020// DiscoveryPlugin is a launchr plugin to discover actions.
2121type DiscoveryPlugin interface {
2222 launchr.Plugin
23- DiscoverActions (fs fs.FS ) ([]* Action , error )
23+ DiscoverActions (fs launchr.ManagedFS ) ([]* Action , error )
24+ }
25+
26+ // DiscoveryFS is a file system to discover actions.
27+ type DiscoveryFS struct {
28+ fs fs.FS
29+ wd string
30+ }
31+
32+ // NewDiscoveryFS creates a DiscoveryFS given fs - a filesystem to discover
33+ // and wd - working directory for an action, leave empty for current path.
34+ func NewDiscoveryFS (fs fs.FS , wd string ) DiscoveryFS { return DiscoveryFS {fs , wd } }
35+
36+ // FS implements launchr.ManagedFS.
37+ func (f DiscoveryFS ) FS () fs.FS { return f .fs }
38+
39+ // Open implements fs.FS and decorates the managed fs.
40+ func (f DiscoveryFS ) Open (name string ) (fs.File , error ) {
41+ return f .FS ().Open (name )
2442}
2543
2644// FileLoadFn is a type for loading a file.
@@ -34,15 +52,15 @@ type DiscoveryStrategy interface {
3452
3553// Discovery defines a common functionality for discovering action files.
3654type Discovery struct {
37- fs fs. FS
38- cwd string
39- s DiscoveryStrategy
55+ fs DiscoveryFS
56+ fsDir string
57+ s DiscoveryStrategy
4058}
4159
4260// NewDiscovery creates an instance of action discovery.
43- func NewDiscovery (fs fs. FS , ds DiscoveryStrategy ) * Discovery {
44- cwd := launchr .GetFsAbsPath (fs )
45- return & Discovery {fs , cwd , ds }
61+ func NewDiscovery (fs DiscoveryFS , ds DiscoveryStrategy ) * Discovery {
62+ fsDir := launchr .GetFsAbsPath (fs )
63+ return & Discovery {fs , fsDir , ds }
4664}
4765
4866func (ad * Discovery ) isValid (path string , d fs.DirEntry ) bool {
@@ -123,7 +141,7 @@ func (ad *Discovery) parseFile(f string) *Action {
123141 if id == "" {
124142 panic (fmt .Errorf ("action id cannot be empty, file %q" , f ))
125143 }
126- a := NewAction (id , ad .cwd , f )
144+ a := NewAction (id , absPath ( ad .fs . wd ), filepath . Join ( ad . fsDir , f ) )
127145 a .Loader = ad .s .Loader (
128146 func () (fs.File , error ) { return ad .fs .Open (f ) },
129147 envProcessor {},
0 commit comments