aboutsummaryrefslogtreecommitdiff
path: root/conf.go
diff options
context:
space:
mode:
Diffstat (limited to 'conf.go')
-rw-r--r--conf.go51
1 files changed, 51 insertions, 0 deletions
diff --git a/conf.go b/conf.go
new file mode 100644
index 0000000..71b2919
--- /dev/null
+++ b/conf.go
@@ -0,0 +1,51 @@
+package main
+
+import (
+ "errors"
+ "os"
+ "path/filepath"
+)
+
+type Conf struct {
+ Source string
+ Dest string
+}
+
+func loadConf() (*Conf, error) {
+ source := os.Getenv("CONF_SOURCE")
+ info, err := os.Stat(source)
+ if err != nil {
+ return nil, err
+ }
+ if !info.IsDir() {
+ return nil, errors.New("CONF_SOURCE is not a directory")
+ }
+ home, err := os.UserHomeDir()
+ if err != nil {
+ return nil, err
+ }
+ return &Conf{Source: source, Dest: home}, nil
+}
+
+func (c *Conf) FileNames() ([]string, error) {
+ var names []string
+ dir := filepath.Join(c.Source, "templates")
+ err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
+ if err != nil {
+ return err
+ }
+ if info.IsDir() {
+ return nil
+ }
+ name, err := filepath.Rel(dir, path)
+ if err != nil {
+ return err
+ }
+ names = append(names, name)
+ return nil
+ })
+ if err != nil {
+ return nil, err
+ }
+ return names, nil
+}