package main import ( "errors" "fmt" "os" ) type Conf struct { Source string Dest string } func main() { conf, err := loadConf() if err != nil { fmt.Printf("could not load configuration: %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 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 }