aboutsummaryrefslogtreecommitdiff
path: root/conf.go
diff options
context:
space:
mode:
authorBen Burwell <ben@benburwell.com>2020-06-06 17:02:38 -0400
committerBen Burwell <ben@benburwell.com>2020-06-06 17:02:38 -0400
commitda8aa52b5ce6d948a346d7dbf1254ca3faaeac80 (patch)
tree503ed27704aab39c824abcbd8a08d4f60fb39e49 /conf.go
parent34060154caf34fc8d709135be803e08855496614 (diff)
Add status subcommandstatus
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
+}