本文整理汇总了Golang中github.com/briandowns/spinner.Spinner.Color方法的典型用法代码示例。如果您正苦于以下问题:Golang Spinner.Color方法的具体用法?Golang Spinner.Color怎么用?Golang Spinner.Color使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/briandowns/spinner.Spinner
的用法示例。
在下文中一共展示了Spinner.Color方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: installPackage
func installPackage(repo string) error {
wd, err := os.Getwd()
if err != nil {
return errors.Trace(err)
}
gopath := os.Getenv("GOPATH")
packageDir := path.Join(gopath, "src", getRealRepoPath(repo))
defer func() {
_ = os.Chdir(wd)
}()
err = os.Chdir(packageDir)
if err != nil {
return errors.Trace(err)
}
var s *spinner.Spinner
if Verbose {
s = spinner.New(spinner.CharSets[SpinnerCharSet], SpinnerInterval)
s.Prefix = fmt.Sprintf(" - installing package %s ", repo)
s.Color("green")
s.Start()
}
goInstallCommand := []string{"go", "install", repo}
goInstallOutput, err := exec.Command(goInstallCommand[0], goInstallCommand[1:]...).CombinedOutput()
if Verbose {
s.Stop()
fmt.Printf("\r - installing package %s ... %s\n", repo, color.GreenString("done"))
}
if err != nil {
return errors.Annotatef(err, "failed installing package %s, error: %s, output: %s", repo, goInstallOutput)
}
return nil
}
示例2: fetchPackage
func fetchPackage(repo string) error {
wd, err := os.Getwd()
if err != nil {
return errors.Trace(err)
}
gopath := os.Getenv("GOPATH")
packageDir := path.Join(gopath, "src", getRealRepoPath(repo))
if _, err := os.Stat(packageDir); err != nil {
if os.IsNotExist(err) {
var s *spinner.Spinner
if Verbose {
s = spinner.New(spinner.CharSets[SpinnerCharSet], SpinnerInterval)
s.Prefix = fmt.Sprintf("fetching %s ", repo)
s.Color("green")
s.Start()
}
goGetCommand := []string{"go", "get", "-d", repo}
goGetCmd := exec.Command(goGetCommand[0], goGetCommand[1:]...)
err := goGetCmd.Run()
if Verbose {
s.Stop()
}
if err != nil {
return errors.Annotatef(err, "failed cloning repo for package %s", repo)
} else {
if Verbose {
fmt.Printf("\rfetching %s ... %s\n", repo, color.GreenString("done"))
}
}
return nil
}
}
defer func() {
_ = os.Chdir(wd)
}()
packageDir, err = getPackageRootDir(getRealRepoPath(repo))
if err != nil {
return errors.Trace(err)
}
err = os.Chdir(packageDir)
if err != nil {
return errors.Trace(err)
}
var s *spinner.Spinner
if Verbose {
s = spinner.New(spinner.CharSets[SpinnerCharSet], SpinnerInterval)
s.Prefix = fmt.Sprintf("refreshing %s ", repo)
s.Color("green")
s.Start()
}
var refreshCommand []string
if exists, _ := pathExists(path.Join(packageDir, ".git")); exists {
refreshCommand = []string{"git", "fetch", "--all"}
} else if exists, _ := pathExists(path.Join(packageDir, ".hg")); exists {
refreshCommand = []string{"hg", "pull"}
} else if exists, _ := pathExists(path.Join(packageDir, ".bzr")); exists {
refreshCommand = []string{"bzr", "pull"}
} else if exists, _ := pathExists(path.Join(packageDir, ".svn")); exists {
refreshCommand = []string{"svn", "up"}
}
if len(refreshCommand) > 0 {
refreshOutput, err := exec.Command(refreshCommand[0], refreshCommand[1:]...).CombinedOutput()
if Verbose {
s.Stop()
fmt.Printf("\rrefreshing %s ... %s\n", repo, color.GreenString("done"))
}
if err != nil {
return errors.Annotatef(err, "failed updating repo for package %s, output: %s", repo, refreshOutput)
}
} else {
if Verbose {
s.Stop()
fmt.Printf("\rrefreshing %s ... %s\n", repo, color.YellowString("skipped"))
}
}
return nil
}
示例3: setPackageVersion
func setPackageVersion(repo string, version string, humanVersion string) error {
if version == "" {
return nil
}
wd, err := os.Getwd()
if err != nil {
return errors.Trace(err)
}
packageDir, err := getPackageRootDir(getRealRepoPath(repo))
if err != nil {
return errors.Trace(err)
}
defer func() {
_ = os.Chdir(wd)
}()
err = os.Chdir(packageDir)
if err != nil {
return errors.Trace(err)
}
var checkoutCommand []string
if exists, _ := pathExists(".git"); exists {
checkoutCommand = []string{"git", "checkout", version}
} else if exists, _ := pathExists(".hg"); exists {
checkoutCommand = []string{"hg", "update", "-c", version}
} else if exists, _ := pathExists(".bzr"); exists {
if version != "" {
checkoutCommand = []string{"bzr", "update", "-r", version}
} else {
checkoutCommand = []string{"bzr", "update"}
}
} else {
if Verbose {
fmt.Printf(" - setting version of %s to %s (resolved as %s) ... %s\n", repo, humanVersion, version, color.GreenString("skipped, unknown repo type"))
}
return nil
}
var s *spinner.Spinner
if Verbose {
s = spinner.New(spinner.CharSets[SpinnerCharSet], SpinnerInterval)
s.Prefix = fmt.Sprintf(" - setting version of %s to %s (resolved as %s) ", repo, humanVersion, version)
s.Color("green")
s.Start()
}
checkoutOutput, err := exec.Command(checkoutCommand[0], checkoutCommand[1:]...).CombinedOutput()
if Verbose {
s.Stop()
fmt.Printf("\r - setting version of %s to %s (resolved as %s) ... %s\n", repo, humanVersion, version, color.GreenString("done"))
}
if err != nil {
return errors.Annotatef(err, "failed setting version of package %s, error: %s, output: %s", repo, checkoutOutput)
}
return nil
}