Example #1
0
//ReadRecursively - get frozen dependencies recursively
func ReadRecursively(deps dep.DependencyMap, set map[string]string) (result string) {
	var err error

	if set == nil {
		util.Print(colors.Yellow("NOTE: This will not reflect the state of the remote unless you have just run `depman install`."))

		set = make(map[string]string)
	}

	for name, d := range deps.Map {
		var subPath string
		var depsFile string
		var subDeps dep.DependencyMap

		if _, ok := set[d.Repo]; ok {
			continue
		}

		if d.Type == dep.TypeGitClone && d.Alias == "" {
			util.PrintIndent(colors.Red("Error: Repo '" + name + "' Type '" + d.Type + "' requires 'alias' field (defined in " + deps.Path + ")"))
			continue
		}

		{
			var temp string

			temp, err = d.VCS.GetHead(d)
			if err != nil {
				util.Fatal(err)
			}

			set[d.Repo] = temp
			result += fmt.Sprintf("%s %s\n", d.Repo, temp)
		}

		subPath = d.Path()

		// Recursive
		depsFile = util.UpwardFind(subPath, dep.DepsFile)
		if depsFile != "" {
			subDeps, err = dep.Read(depsFile)
			if err == nil {
				result += ReadRecursively(subDeps, set)
			} else {
				util.Print(colors.Yellow("Error reading deps from '" + subDeps.Path + "': " + err.Error()))
			}
		}
	}
	return
}
Example #2
0
func main() {
	var help bool
	var path string
	var command string
	var arguments []string
	var deps dep.DependencyMap
	var err error

	log.SetFlags(0)

	flag.BoolVar(&help, "help", false, "Display help")
	flag.StringVar(&path, "path", ".", "Directory or full path to deps.json")
	util.Parse()

	util.Version(VERSION)

	fmt.Println(colors.Red("Depman was deprecated on 25 February 2015"))
	fmt.Println(colors.Red("We recommend using 'godep' instead: https://github.com/tools/godep"))

	util.GoPathIsSet()

	if timelock.Clear() {
		return
	}

	timelock.Read()

	// check for a new version of depman
	go upgrade.Check(VERSION)
	runtime.Gosched()
	defer upgrade.Print()

	path = dep.GetPath(path)

	if flag.NArg() > 0 {
		command = strings.ToLower(flag.Arg(0))
	}

	if flag.NArg() > 1 {
		arguments = flag.Args()[1:]
	}

	if help {
		command = "help"
	}

	// switch to check for deps.json
	switch command {
	case "add", "", "install", "update", "show-frozen":
		// check for deps.json
		util.CheckPath(path)
		deps, err = dep.Read(path)
		if err != nil {
			util.Fatal(colors.Red("Error Reading deps.json: " + err.Error()))
		}
	}

	// switch to exec the sub command
	switch command {
	case "init", "create":
		create.Create(path)
	case "add":
		if len(arguments) < 1 {
			util.Print(colors.Red("Add command requires 1 argument: Add [nickname]"))
			Help()
		} else {
			add.Add(deps, arguments[0])
		}

	case "update":
		if len(arguments) < 2 {
			util.Print(colors.Red("Update command requires 2 arguments: Update [nickname] [branch]"))
			Help()
		} else {
			update.Update(deps, arguments[0], arguments[1])
		}
	case "install", "":
		install.Install(deps)
	case "self-upgrade":
		upgrade.Self(VERSION)
	case "show-frozen":
		var recursive bool
		flagset := flag.NewFlagSet("show-frozen", flag.ExitOnError)
		flagset.BoolVar(&recursive, "recursive", false, "descend recursively (depth-first) into dependencies")
		flagset.Parse(flag.Args()[1:])

		if recursive {
			fmt.Println(showfrozen.ReadRecursively(deps, nil))
		} else {
			fmt.Print(showfrozen.Read(deps))
		}
	default:
		result.RegisterError()
		log.Println(colors.Red("Unknown Command: " + command))
		fallthrough
	case "help":
		Help()
	}

	timelock.Write()

	if result.ShouldExitWithError() {
		os.Exit(1)
	} else {
		util.Print("Success")
	}
}
Example #3
0
// recursively install a DependencyMap
func recursiveInstall(deps dep.DependencyMap, set map[string]string) (err error) {
	for name, d := range deps.Map {
		start := time.Now()

		if duplicate(*d, set) {
			continue
		}

		stale := timelock.IsStale(d.Repo)

		util.PrintDep(name, d.Version, d.Repo, stale)

		subPath := d.Path()
		err = d.VCS.Clone(d)
		if err != nil {
			continue
		}

		util.Cd(subPath)

		if clean {
			d.VCS.Clean(d)
		}

		if stale {
			util.VerboseIndent(" # repo is stale, fetching")
			err = d.VCS.Fetch(d)
			if err != nil {
				continue
			}
		}

		err = d.VCS.Checkout(d)
		if err != nil {
			continue
		}

		if stale {
			err = d.VCS.Update(d)
			if err != nil {
				continue
			}
		}

		util.VerboseIndent(fmt.Sprintf("# time to install: %.3fs", time.Since(start).Seconds()))

		// Recursive
		depsFile := util.UpwardFind(subPath, dep.DepsFile)
		if depsFile != "" && Recurse {
			subDeps, err := dep.Read(depsFile)
			if err != nil {
				util.Print(colors.Red("Error reading deps from '" + depsFile + "': " + err.Error()))
				result.RegisterError()
			} else {
				util.IncreaseIndent()
				recursiveInstall(subDeps, set)
				util.DecreaseIndent()
			}
		}
	}
	return
}