本文整理汇总了Golang中github.com/briandowns/spinner.Spinner类的典型用法代码示例。如果您正苦于以下问题:Golang Spinner类的具体用法?Golang Spinner怎么用?Golang Spinner使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Spinner类的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
}
开发者ID:abutre,项目名称:bunch,代码行数:41,代码来源:packages.go
示例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
}
开发者ID:abutre,项目名称:bunch,代码行数:93,代码来源:packages.go
示例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
}
开发者ID:abutre,项目名称:bunch,代码行数:64,代码来源:packages.go
注:本文中的github.com/briandowns/spinner.Spinner类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论