From af3c47c7849bb26bf221a84e22e172a147b9485a Mon Sep 17 00:00:00 2001 From: Clayton Craft Date: Fri, 17 Feb 2023 13:25:11 -0800 Subject: [PATCH] filelist/hookscripts: add new implementation --- internal/filelist/hookscripts/hookscripts.go | 32 ++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 internal/filelist/hookscripts/hookscripts.go diff --git a/internal/filelist/hookscripts/hookscripts.go b/internal/filelist/hookscripts/hookscripts.go new file mode 100644 index 0000000..141bdae --- /dev/null +++ b/internal/filelist/hookscripts/hookscripts.go @@ -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 +}