diff options
Diffstat (limited to 'main.go')
-rw-r--r-- | main.go | 35 |
1 files changed, 29 insertions, 6 deletions
@@ -5,24 +5,36 @@ import ( "os" ) -const ( - base = "/Users/ben/dotfiles" - dest = "/Users/ben" -) +type Conf struct { + Source string + Dest string +} func main() { + conf := &Conf{ + Source: os.Getenv("CONF_SOURCE"), + Dest: os.Getenv("CONF_DEST"), + } + if err := checkdir(conf.Source); err != nil { + fmt.Printf("could not find $CONF_SOURCE: %v\n", err) + os.Exit(1) + } + if err := checkdir(conf.Dest); err != nil { + fmt.Printf("could not find $CONF_DEST: %v\n", err) + os.Exit(1) + } if len(os.Args) < 2 { fmt.Printf("usage: conf <adopt|apply> [files...]\n") os.Exit(1) } switch os.Args[1] { case "apply": - if err := apply(os.Args[2:]); err != nil { + if err := apply(conf, os.Args[2:]); err != nil { fmt.Printf("%v\n", err) os.Exit(1) } case "adopt": - if err := adopt(os.Args[2:]); err != nil { + if err := adopt(conf, os.Args[2:]); err != nil { fmt.Printf("%v\n", err) os.Exit(1) } @@ -31,3 +43,14 @@ func main() { os.Exit(1) } } + +func checkdir(path string) error { + info, err := os.Stat(path) + if err != nil { + return err + } + if !info.IsDir() { + return fmt.Errorf("%s is not a directory", path) + } + return nil +} |