From da8aa52b5ce6d948a346d7dbf1254ca3faaeac80 Mon Sep 17 00:00:00 2001 From: Ben Burwell Date: Sat, 6 Jun 2020 17:02:38 -0400 Subject: Add status subcommand --- conf.go | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 conf.go (limited to 'conf.go') 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 +} -- cgit v1.2.3