filelist/hookscripts: add new implementation
This commit is contained in:
32
internal/filelist/hookscripts/hookscripts.go
Normal file
32
internal/filelist/hookscripts/hookscripts.go
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
package hookscripts
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
)
|
||||||
|
|
||||||
|
type HookScripts struct {
|
||||||
|
scriptsDir string
|
||||||
|
}
|
||||||
|
|
||||||
|
// New returns a new HookScripts that will use the given path to provide a list
|
||||||
|
// of script files.
|
||||||
|
func New(scriptsDir string) *HookScripts {
|
||||||
|
return &HookScripts{
|
||||||
|
scriptsDir: scriptsDir,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *HookScripts) List() ([]string, error) {
|
||||||
|
files := []string{}
|
||||||
|
fileInfo, err := os.ReadDir(h.scriptsDir)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("getHookScripts: unable to read hook script dir: %w", err)
|
||||||
|
}
|
||||||
|
for _, file := range fileInfo {
|
||||||
|
path := filepath.Join(h.scriptsDir, file.Name())
|
||||||
|
files = append(files, path)
|
||||||
|
}
|
||||||
|
return files, nil
|
||||||
|
}
|
Reference in New Issue
Block a user