本文整理汇总了Golang中github.com/vube/depman/colors.Red函数的典型用法代码示例。如果您正苦于以下问题:Golang Red函数的具体用法?Golang Red怎么用?Golang Red使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Red函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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
}
示例2: 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
}
示例3: 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
}
示例4: Pwd
// Pwd returns the current working directory
func Pwd() (pwd string) {
pwd, err := os.Getwd()
if err != nil {
logger.Print(colors.Red("Cannot get Current Working Directory"))
Fatal(colors.Red(err.Error()))
}
return
}
示例5: defaultCd
// Change directory to the specified directory, checking for errors
// Returns the path to the old working directory
func defaultCd(dir string) (err error) {
err = os.Chdir(dir)
if err != nil {
result.RegisterError()
logger.Output(2, indent()+colors.Red("$ cd "+dir))
logger.Output(2, indent()+colors.Red(err.Error()))
} else if verbose {
logger.Output(2, indent()+"$ cd "+dir)
}
return
}
示例6: 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
}
示例7: 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
}
示例8: 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
}
示例9: 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
}
示例10: 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
}
示例11: 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
}
示例12: 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
}
示例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
}
示例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
}
示例15: 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..."))
}
}
}