func installFn(cmd *Command, args []string) error { configureLogging() if len(args) > 0 { return fmt.Errorf("Too many arguments for 'install'") } // set unset paramters to the defaults if lockFileName == "" { lockFileName = defaultLockFileName } if targetPath == "" { targetPath = defaultTargetPath } log.Debug("lock file: %v", lockFileName) log.Debug("target path: %v", targetPath) // get dependencies from the lockfile deplist, err := LoadGrapnelDepsfile(lockFileName) if err != nil { return err } else if deplist == nil { // TODO: fail over to update instead? return fmt.Errorf("Cannot open lock file: '%s'", lockFileName) } log.Info("loaded %d dependency definitions", len(deplist)) log.Info("installing to: %v", targetPath) if err := os.MkdirAll(targetPath, 0755); err != nil { return err } libs := []*Library{} // cleanup defer func() { for _, lib := range libs { lib.Destroy() } }() // resolve all the dependencies resolver, err := getResolver() if err != nil { return err } libs, err = resolver.ResolveDependencies(deplist) if err != nil { return err } // install all the dependencies log.Info("Resolved %v dependencies. Installing.", len(libs)) resolver.InstallLibraries(targetPath, libs) log.Info("Install complete") return nil }
func updateFn(cmd *Command, args []string) error { configureLogging() if len(args) > 0 { return fmt.Errorf("Too many arguments for 'update'") } // set unset paramters to the defaults if packageFileName == "" { packageFileName = defaultPackageFileName if lockFileName == "" { // set to default iff there was no package filename set lockFileName = defaultLockFileName } } else if lockFileName == "" { // compose a new lock file path out of the old package path lockFileName = path.Join(path.Dir(packageFileName), "grapnel-lock.toml") } if targetPath == "" { targetPath = defaultTargetPath } log.Debug("package file: %v", packageFileName) log.Debug("lock file: %v", lockFileName) log.Debug("target path: %v", targetPath) // get dependencies from the grapnel file log.Info("loading package file: '%s'", packageFileName) deplist, err := LoadGrapnelDepsfile(packageFileName) if err != nil { return err } else if deplist == nil { // TODO: fail over to update instead? return fmt.Errorf("Cannot open grapnel file: '%s'", packageFileName) } log.Info("loaded %d dependency definitions", len(deplist)) // open it now before we expend any real effort lockFile, err := os.Create(lockFileName) defer lockFile.Close() if err != nil { log.Error("Cannot open lock file: '%s'", lockFileName) return err } log.Info("installing to: %v", targetPath) if err := os.MkdirAll(targetPath, 0755); err != nil { return err } libs := []*Library{} // cleanup defer func() { for _, lib := range libs { lib.Destroy() } }() // resolve all the dependencies resolver, err := getResolver() if err != nil { return err } libs, err = resolver.ResolveDependencies(deplist) if err != nil { return err } // install all the dependencies log.Info("Resolved %v dependencies. Installing.", len(libs)) resolver.InstallLibraries(targetPath, libs) // write the library data out log.Info("Writing lock file") for _, lib := range libs { lib.ToToml(lockFile) } if createDsd { log.Info("Writing dsd file") dsdFileName := path.Join(path.Dir(lockFileName), "grapnel-dsd.sh") if err := resolver.ToDsd(dsdFileName, libs); err != nil { return err } } log.Info("Update complete") return nil }