package main import ( "fmt" "os" ) 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 [files...]\n") os.Exit(1) } switch os.Args[1] { case "apply": if err := apply(conf, os.Args[2:]); err != nil { fmt.Printf("%v\n", err) os.Exit(1) } case "adopt": if err := adopt(conf, os.Args[2:]); err != nil { fmt.Printf("%v\n", err) os.Exit(1) } default: fmt.Printf("unrecognized command: %s\n", os.Args[1]) 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 }