Esempio n. 1
0
// setup configuration options
func init() {
	var err error
	if currentUser, err = user.Current(); err != nil {
		log.Fatal(err)
	}

	configo.StringVar(&spoolPath, "spooldir", filepath.Join(currentUser.HomeDir, "spool"), "The directory to look in for new pictures to spool.")
	configo.StringVar(&basePhotoPath, "photodir", filepath.Join(currentUser.HomeDir, "Pictures"), "The directory that new pictures will be copied to as they are spooled.")
	configo.StringVar(&errorPath, "errordir", filepath.Join(currentUser.HomeDir, "spool_error"), "The directory to copy pictures to when an error occurs.")
	configo.StringVar(&md5DbPath, "dbdir", filepath.Join(currentUser.HomeDir, ".photo-spool.db"), "The full path to the photo database file.")
	configo.BoolFlagVar(&noop, "dryrun", false, "If set the program has no effect but prints what would have happened.")

	if err = configo.Parse(); err != nil {
		panic(err)
	}

	if err := os.MkdirAll(errorPath, 0775); err != nil {
		log.Fatal(err)
	}

	if err := os.MkdirAll(basePhotoPath, 0775); err != nil {
		log.Fatal(err)
	}

	if err := os.MkdirAll(spoolPath, 0775); err != nil {
		log.Fatal(err)
	}

	if spool, err = spooler.New(md5DbPath, basePhotoPath, errorPath, noop); err != nil {
		log.Fatalf("Could not create a new Spool. %v\n", err)
	}
}
Esempio n. 2
0
func init() {
	const (
		defaultGopher = "pocket"
		usage         = "the variety of gopher"
	)
	configo.StringVar(&gopherType, "gopher_type", defaultGopher, usage)
	// shorthand version is not valid in the config file
	configo.StringVar(&gopherType, "g", defaultGopher, usage+" (shorthand)")
}