diff options
author | Ben Burwell <ben@benburwell.com> | 2020-06-06 17:02:38 -0400 |
---|---|---|
committer | Ben Burwell <ben@benburwell.com> | 2020-06-06 17:02:38 -0400 |
commit | da8aa52b5ce6d948a346d7dbf1254ca3faaeac80 (patch) | |
tree | 503ed27704aab39c824abcbd8a08d4f60fb39e49 /conf.go | |
parent | 34060154caf34fc8d709135be803e08855496614 (diff) |
Add status subcommandstatus
Diffstat (limited to 'conf.go')
-rw-r--r-- | conf.go | 51 |
1 files changed, 51 insertions, 0 deletions
@@ -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 +} |