github.com/kngu9/glide@v0.0.0-20160505135211-e73500c73591/action/remove.go (about) 1 package action 2 3 import ( 4 "github.com/Masterminds/glide/cfg" 5 "github.com/Masterminds/glide/msg" 6 gpath "github.com/Masterminds/glide/path" 7 "github.com/Masterminds/glide/repo" 8 ) 9 10 // Remove removes a dependncy from the configuration. 11 func Remove(packages []string, inst *repo.Installer) { 12 base := gpath.Basepath() 13 EnsureGopath() 14 EnsureVendorDir() 15 conf := EnsureConfig() 16 glidefile, err := gpath.Glide() 17 if err != nil { 18 msg.Die("Could not find Glide file: %s", err) 19 } 20 21 msg.Info("Preparing to remove %d packages.", len(packages)) 22 conf.Imports = rmDeps(packages, conf.Imports) 23 conf.DevImports = rmDeps(packages, conf.DevImports) 24 25 // Copy used to generate locks. 26 confcopy := conf.Clone() 27 28 confcopy.Imports = inst.List(confcopy) 29 30 if err := repo.SetReference(confcopy); err != nil { 31 msg.Err("Failed to set references: %s", err) 32 } 33 34 // TODO: Right now, there is no flag to enable this, so this will never be 35 // run. I am not sure whether we should allow this in a rm op or not. 36 if inst.UpdateVendored { 37 repo.VendoredCleanup(confcopy) 38 } 39 40 // Write glide.yaml 41 if err := conf.WriteFile(glidefile); err != nil { 42 msg.Die("Failed to write glide YAML file: %s", err) 43 } 44 45 // Write glide lock 46 writeLock(conf, confcopy, base) 47 } 48 49 // rmDeps returns a list of dependencies that do not contain the given pkgs. 50 // 51 // It generates neither an error nor a warning for a pkg that does not exist 52 // in the list of deps. 53 func rmDeps(pkgs []string, deps []*cfg.Dependency) []*cfg.Dependency { 54 res := []*cfg.Dependency{} 55 for _, d := range deps { 56 rem := false 57 for _, p := range pkgs { 58 if p == d.Name { 59 rem = true 60 } 61 } 62 if !rem { 63 res = append(res, d) 64 } 65 } 66 return res 67 }