• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang util.Print函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/vube/depman/util.Print函数的典型用法代码示例。如果您正苦于以下问题:Golang Print函数的具体用法?Golang Print怎么用?Golang Print使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了Print函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: Create

// 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
}
开发者ID:pombredanne,项目名称:depman,代码行数:14,代码来源:create.go


示例2: ReadRecursively

//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
}
开发者ID:nicholascapo,项目名称:depman,代码行数:51,代码来源:showfrozen.go


示例3: duplicate

// Check for duplicate dependency
// if same name and same version, skip
// if same name and different version, exit
// if different name, add to set, don't skip
func duplicate(d dep.Dependency, set map[string]string) (skip bool) {
	version, installed := set[d.Repo]
	if installed && version != d.Version {
		util.Print(colors.Red("ERROR    : Duplicate dependency with different versions detected"))
		util.Print(colors.Red("Repo     : " + d.Repo))
		util.Fatal(colors.Red("Versions : " + d.Version + "\t" + version))
	} else if installed {
		util.VerboseIndent(colors.Yellow("Skipping previously installed dependency: ") + d.Repo)
		skip = true
	} else {
		set[d.Repo] = d.Version
	}
	return
}
开发者ID:pombredanne,项目名称:depman,代码行数:18,代码来源:install.go


示例4: Read

//Read - get top-level frozen dependencies
func Read(deps dep.DependencyMap) (result string) {
	var err error
	var resultMap = make(map[string]*dep.Dependency)

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

	for k, v := range deps.Map {
		if v.Type == dep.TypeGitClone && v.Alias == "" {
			util.PrintIndent(colors.Red("Error: Repo '" + k + "' Type '" + v.Type + "' requires 'alias' field (defined in " + deps.Path + ")"))
			continue
		}

		v.Version, err = v.VCS.GetHead(v)
		if err != nil {
			util.Fatal(err)
		}

		resultMap[k] = v
	}

	//not changing the logic in the loop because we might want to change the print format later
	for _, v := range resultMap {
		result += fmt.Sprintf("%s %s\n", v.Repo, v.Version)
	}

	return
}
开发者ID:nicholascapo,项目名称:depman,代码行数:28,代码来源:showfrozen.go


示例5: GetHead

//GetHead - Render a revspec to a commit ID
func (g *Git) GetHead(d *Dependency) (hash string, err error) {
	var pwd string

	pwd = util.Pwd()
	util.Cd(d.Path())

	c := exec.Command("git", "rev-parse", d.Version)
	{
		var out_bytes []byte
		out_bytes, err = c.CombinedOutput()
		hash = strings.TrimSuffix(string(out_bytes), "\n")
	}

	util.Cd(pwd)

	if err != nil {
		util.Print("pwd: " + util.Pwd())
		util.PrintIndent(colors.Red("git rev-parse " + d.Version))
		util.PrintIndent(colors.Red(string(hash)))
		util.PrintIndent(colors.Red(err.Error()))
		util.Fatal("")
	}

	return
}
开发者ID:pombredanne,项目名称:depman,代码行数:26,代码来源:git.go


示例6: SetupVCS

// SetupVCS configures the VCS depending on the type
func (d *Dependency) SetupVCS(name string) (err error) {
	switch d.Type {
	case TypeGitClone:
		if d.Alias == "" {
			util.PrintIndent(colors.Red("Error: Dependency " + name + ": Repo '" + d.Repo + "' Type '" + d.Type + "' requires 'alias' field"))
			err = ErrMissingAlias
			return
		}

		d.VCS = new(Git)
	case TypeGit:
		d.VCS = new(Git)
	case TypeBzr:
		d.VCS = new(Bzr)
	case TypeHg:
		d.VCS = new(Hg)
	default:
		util.PrintIndent(colors.Red(d.Repo + ": Unknown repository type (" + d.Type + "), skipping..."))
		util.PrintIndent(colors.Red("Valid Repository types: " + TypeGit + ", " + TypeHg + ", " + TypeBzr + ", " + TypeGitClone))
		err = ErrUnknownType
	}

	if d.Type != TypeGitClone && d.Alias != "" {
		util.Print(colors.Yellow("Warning: " + d.Repo + ": 'alias' field only allowed in dependencies with type 'git-clone', skipping..."))
		d.Alias = ""
	}

	return
}
开发者ID:nicholascapo,项目名称:depman,代码行数:30,代码来源:dep.go


示例7: isBranch

// IsBranch determines if a version (branch, commit hash, tag) is a branch (i.e. can we pull from the remote).
// Assumes we are already in a sub directory of the repo
func (g *Git) isBranch(name string) (result bool) {
	c := exec.Command("git", "branch", "-r")
	out, err := c.CombinedOutput()

	if err != nil {
		util.Print("pwd: " + util.Pwd())
		util.PrintIndent(colors.Red("git branch -r"))
		util.PrintIndent(colors.Red(string(out)))
		util.PrintIndent(colors.Red(err.Error()))
		return false
	}

	// get the string version but also strip the trailing newline
	stringOut := string(out[0 : len(out)-1])

	lines := strings.Split(stringOut, "\n")
	for _, val := range lines {
		// for "origin/HEAD -> origin/master"
		arr := strings.Split(val, " -> ")
		remoteBranch := arr[0]

		// for normal "origin/develop"
		arr = strings.Split(remoteBranch, "/")
		branch := arr[1]
		if branch == name {
			return true
		}
	}

	return
}
开发者ID:nicholascapo,项目名称:depman,代码行数:33,代码来源:git.go


示例8: Self

// 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")
	}
}
开发者ID:nicholascapo,项目名称:depman,代码行数:22,代码来源:upgrade.go


示例9: promptType

// Prompt the user with question check that the answer is a valid dep type and then return it
func promptType(question string, details string) (t string) {
	for {
		t = promptString(question, details)
		t = strings.TrimSpace(t)
		switch t {
		case dep.TypeBzr, dep.TypeGit, dep.TypeHg, dep.TypeGitClone:
			return
		default:
			util.Print(colors.Red("Invalid Type, try again..."))
		}
	}
}
开发者ID:pombredanne,项目名称:depman,代码行数:13,代码来源:add.go


示例10: LastCommit

// LastCommit retrieves the version number of the last commit on branch
// Assumes that the current working directory is in the hg repo
func (h *Hg) LastCommit(d *Dependency, branch string) (hash string, err error) {
	c := exec.Command("hg", "log", "--template='{node}\n'", "--limit=1")
	out, err := c.CombinedOutput()

	if err != nil {
		util.Print("pwd: " + util.Pwd())
		util.PrintIndent(colors.Red("hg log --template='{node}\n' --limit=1"))
		util.PrintIndent(colors.Red(string(out)))
		util.PrintIndent(colors.Red(err.Error()))
		util.Fatal("")
	}

	hash = strings.Replace(string(out), "\n", "", -1)
	return
}
开发者ID:pombredanne,项目名称:depman,代码行数:17,代码来源:hg.go


示例11: LastCommit

// LastCommit retrieves the version number of the last commit on branch
// Assumes that the current working directory is in the bzr repo
func (b *Bzr) LastCommit(d *Dependency, branch string) (hash string, err error) {
	c := exec.Command("bzr", "log", "--line")
	out, err := c.CombinedOutput()

	if err != nil {
		util.Print("pwd: " + util.Pwd())
		util.PrintIndent(colors.Red("bzr log --line"))
		util.PrintIndent(colors.Red(string(out)))
		util.PrintIndent(colors.Red(err.Error()))
		util.Fatal("")
	}

	hash = strings.Split(string(out), ":")[0]
	return
}
开发者ID:nicholascapo,项目名称:depman,代码行数:17,代码来源:bzr.go


示例12: Add

// 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
}
开发者ID:pombredanne,项目名称:depman,代码行数:43,代码来源:add.go


示例13: GetHead

//GetHead - Render a revspec to a commit ID
func (h *Hg) GetHead(d *Dependency) (hash string, err error) {
	var pwd string

	pwd = util.Pwd()
	util.Cd(d.Path())
	defer util.Cd(pwd)

	out, err := exec.Command("hg", "id", "-i").CombinedOutput()
	hash = strings.TrimSuffix(string(out), "\n")

	if err != nil {
		util.Print("pwd: " + util.Pwd())
		util.PrintIndent(colors.Red("hg id -i"))
		util.PrintIndent(colors.Red(hash))
		util.PrintIndent(colors.Red(err.Error()))
		util.Fatal("")
	}

	return
}
开发者ID:nicholascapo,项目名称:depman,代码行数:21,代码来源:hg.go


示例14: LastCommit

// LastCommit retrieves the version number of the last commit on branch
// Assumes that the current working directory is in the git repo
func (g *Git) LastCommit(d *Dependency, branch string) (hash string, err error) {
	if !g.isBranch(branch) {
		err = errors.New("Branch '" + branch + "' is not a valid branch")
		return
	}

	c := exec.Command("git", "log", "-1", "--format=%H")
	out, err := c.CombinedOutput()

	if err != nil {
		util.Print("pwd: " + util.Pwd())
		util.PrintIndent(colors.Red("git log -1 --format=%H"))
		util.PrintIndent(colors.Red(string(out)))
		util.PrintIndent(colors.Red(err.Error()))
		util.Fatal("")
	}

	hash = strings.Replace(string(out), "\n", "", -1)
	return
}
开发者ID:nicholascapo,项目名称:depman,代码行数:22,代码来源:git.go


示例15: GetHead

//GetHead - Render a revspec to a commit ID
func (b *Bzr) GetHead(d *Dependency) (hash string, err error) {
	var pwd string

	pwd = util.Pwd()
	util.Cd(d.Path())
	defer util.Cd(pwd)

	out, err := exec.Command("bzr", "revno", d.Version).CombinedOutput()
	hash = strings.TrimSuffix(string(out), "\n")

	if err != nil {
		util.Print("pwd: " + util.Pwd())
		util.PrintIndent(colors.Red("bzr revno " + d.Version))
		util.PrintIndent(colors.Red(hash))
		util.PrintIndent(colors.Red(err.Error()))
		util.Fatal("")
	}

	return
}
开发者ID:nicholascapo,项目名称:depman,代码行数:21,代码来源:bzr.go


示例16: Clear

// Clear clears the cache, returns true if the cache was cleared
func Clear() (cleared bool) {
	cleared = clear

	if clear {
		parts := strings.Split(os.Getenv("GOPATH"), ":")
		cacheFile = filepath.Join(parts[0], cacheFileName)

		util.Print(colors.Yellow("Clearing cache file: " + cacheFile))

		_, err := os.Stat(cacheFile)
		if err != nil {
			return
		}

		err = os.Remove(cacheFile)
		if err != nil {
			util.Fatal(err)
		}
	}

	return
}
开发者ID:nicholascapo,项目名称:depman,代码行数:23,代码来源:timelock.go


示例17: Update

// 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)

}
开发者ID:nicholascapo,项目名称:depman,代码行数:38,代码来源:update.go


示例18: GetHead

//GetHead - Render a revspec to a commit ID
func (h *Hg) GetHead(d *Dependency) (hash string, err error) {
	var pwd string

	pwd = util.Pwd()
	util.Cd(d.Path())

	{
		var out_bytes []byte
		out_bytes, err = exec.Command("hg", "id", "-i", d.Version).CombinedOutput()
		hash = strings.TrimSuffix(string(out_bytes), "\n")
	}

	util.Cd(pwd)

	if err != nil {
		util.Print("pwd: " + util.Pwd())
		util.PrintIndent(colors.Red("hg id -i " + d.Version))
		util.PrintIndent(colors.Red(hash))
		util.PrintIndent(colors.Red(err.Error()))
		util.Fatal("")
	}

	return
}
开发者ID:pombredanne,项目名称:depman,代码行数:25,代码来源:hg.go


示例19: main

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()
//.........这里部分代码省略.........
开发者ID:nicholascapo,项目名称:depman,代码行数:101,代码来源:main.go


示例20: recursiveInstall

// 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
}
开发者ID:pombredanne,项目名称:depman,代码行数:63,代码来源:install.go



注:本文中的github.com/vube/depman/util.Print函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang util.RunCommand函数代码示例发布时间:2022-05-28
下一篇:
Golang util.Fatal函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap