예제 #1
0
파일: util.go 프로젝트: nicholascapo/depman
// PrintDep displays a dependency based on the --silent and --verbose flags
func PrintDep(name string, version string, repo string, stale bool) {
	var staleMarker string

	if stale {
		staleMarker = " *"
	}

	if !silent {
		if verbose {
			logger.Output(2, indent()+colors.Blue(name)+colors.Yellow(" ("+version+")")+" "+repo+staleMarker)
		} else {
			logger.Output(2, indent()+colors.Blue(name)+colors.Yellow(" ("+version+")")+staleMarker)
		}
	}
}
예제 #2
0
// Create writes an empty deps.json at the location specified by path
func Create(path string) {
	if util.Exists(path) {
		util.Fatal(colors.Red(dep.DepsFile + " already exists!"))
	}
	util.Print(colors.Blue("Initializing:"))
	err := ioutil.WriteFile(path, []byte(template), 0644)
	if err == nil {
		util.Print("Empty " + dep.DepsFile + " created (" + path + ")")
	} else {
		util.Fatal(colors.Red("Error creating "+dep.DepsFile+": "), err)
	}
	return
}
예제 #3
0
// Update rewrites Dependency name in deps.json to use the last commit in branch as version
func Update(deps dep.DependencyMap, name string, branch string) {
	util.Print(colors.Blue("Updating:"))

	d, ok := deps.Map[name]
	if !ok {
		util.Fatal(colors.Red("Dependency Name '" + name + "' not found in deps.json"))
	}

	// record the old version
	oldVersion := d.Version

	// temporarily use the branch
	d.Version = branch

	pwd := util.Pwd()
	util.Cd(d.Path())
	d.VCS.Checkout(d)
	d.VCS.Update(d)

	// get the last commit on the newly checked out branch
	v, err := d.VCS.LastCommit(d, branch)
	if err != nil {
		util.Fatal(err)
	}

	// set the version to be the last commit
	d.Version = v

	util.PrintIndent(colors.Blue(name) + " (" + oldVersion + " --> " + d.Version + ")")

	util.Cd(pwd)
	deps.Map[name] = d
	deps.Write()

	install.Install(deps)

}
예제 #4
0
파일: add.go 프로젝트: pombredanne/depman
// Add interactively prompts the user for details of a dependency, adds it to deps.json, and writes out the file
func Add(deps dep.DependencyMap, name string) {
	var cont = true
	_, exists := deps.Map[name]
	if exists {
		util.Fatal(colors.Red("Dependency '" + name + "'' is already defined, pick another name."))
	}

	util.Print(colors.Blue("Adding: ") + name)

	for cont {
		d := new(dep.Dependency)
		d.Type = promptType("Type", "git, git-clone, hg, bzr")
		if d.Type == dep.TypeGitClone {
			d.Repo = promptString("Repo", "git url")
		} else {
			d.Repo = promptString("Repo", "go import")
		}
		d.Version = promptString("Version", "hash, branch, or tag")
		if d.Type == dep.TypeGitClone {
			d.Alias = promptString("Alias", "where to install the repo")
		}
		deps.Map[name] = d
		cont = promptBool("Add another", "y/N")
	}

	for name, d := range deps.Map {
		err := d.SetupVCS(name)
		if err != nil {
			delete(deps.Map, name)
		}

	}

	err := deps.Write()
	if err != nil {
		util.Fatal(colors.Red("Error Writing " + deps.Path + ": " + err.Error()))
	}

	install.Install(deps)

	return
}
예제 #5
0
// Self upgrades this version of depman to the latest on the master branch
func Self(version string) {
	selfCalled = true
	util.Print(colors.Blue("Upgrading depman..."))
	util.RunCommand("go get -u github.com/vube/depman")

	cmd := exec.Command("depman", "--version")
	out, err := cmd.CombinedOutput()
	if err != nil {
		result.RegisterError()
		util.Print(colors.Red(string(out)))
		return
	}

	newVersion := strings.TrimSuffix(strings.TrimPrefix(string(out), "Depman Version "), "\n")

	if newVersion != version {
		util.Print("Upgraded to Version " + newVersion)
	} else {
		util.Print("No upgrade found")
	}
}
예제 #6
0
파일: git.go 프로젝트: nicholascapo/depman
// Clean cleans a git repo: `git reset --hard HEAD ; git clean -fd`
func (g *Git) Clean(d *Dependency) {
	util.PrintIndent(colors.Red("Cleaning:") + colors.Blue(" git reset --hard HEAD"))
	util.RunCommand("git reset --hard HEAD")
	util.RunCommand("git clean -fd")
	return
}
예제 #7
0
// Install a DependencyMap
func Install(deps dep.DependencyMap) error {
	util.Print(colors.Blue("Installing:"))
	set := make(map[string]string)
	return recursiveInstall(deps, set)
}
예제 #8
0
파일: add.go 프로젝트: pombredanne/depman
// Promt the user with question and return a string answer
func promptString(question string, details string) (answer string) {
	fmt.Print(colors.Blue(question) + " (" + details + "): ")
	fmt.Scanln(&answer)
	return
}
예제 #9
0
파일: hg.go 프로젝트: pombredanne/depman
func (h *Hg) Clean(d *Dependency) {
	util.PrintIndent(colors.Red("Cleaning:") + colors.Blue(" hg up --clean "+d.Version))
	util.RunCommand("hg up --clean " + d.Version)
	return
}