예제 #1
0
func runInstall(cmd *cobra.Command, args []string) {
	p, err := pkg.ReadCaddyJSON()
	if err != nil {
		log.Fatal(err)
		return
	}

	if len(args) >= 1 {
		name := args[0]
		fmt.Printf("\n      Installing %s...", name)
		s := spinner.New(spinner.CharSets[21], 100*time.Millisecond) // Build our new spinner
		s.Start()
		defer s.Stop()
		dep, err := pkg.Parse(name, "*")
		if err != nil {
			fmt.Printf(" [\033[0;31mERR\033[0m]\n")
			fmt.Printf("\t  \033[0;31m%s\033[0m\n", err)
			return
		}
		err = install.Download(isGlobal, &dep)
		if err != nil {
			fmt.Printf(" [\033[0;31mERR\033[0m]\n")
			fmt.Printf("\t  \033[0;31m%s\033[0m\n", err)
			return
		}
		fmt.Printf("\r[\033[0;32mOK\033[0m]")
		fmt.Printf("\n\n")
		if save {
			p.RawDependencies[dep.Name] = dep.Spec
			pkg.WriteCaddyJSON(p)
		}
	} else {
		for _, dep := range p.Dependencies {
			fmt.Printf("\n      Installing %s@%s...", dep.Name, dep.Spec)
			s := spinner.New(spinner.CharSets[21], 100*time.Millisecond) // Build our new spinner
			s.Start()
			defer s.Stop()
			err := install.Download(isGlobal, &dep)
			if err != nil {
				fmt.Printf(" [\033[0;31mERR\033[0m]\n")
				fmt.Printf("\t  \033[0;31m%s\033[0m\n", err)
				continue
			}
			fmt.Printf("\r[\033[0;32mOK\033[0m]")
		}
		fmt.Printf("\n\n")
	}

}
예제 #2
0
func main() {
	s := spinner.New(spinner.CharSets[9], 100*time.Millisecond) // Build our new spinner
	s.Color("red")                                              // Set the spinner color to red
	s.FinalMSG = "Complete!\nNew line!\nAnother one!\n"         // String to be displayed after Stop() is called
	s.Start()                                                   // Start the spinner
	time.Sleep(4 * time.Second)                                 // Run for some time to simulate work
	s.Stop()                                                    // Stop the spinner
}
예제 #3
0
파일: 2.go 프로젝트: yujinqiu/spinner
func main() {
	fmt.Println("I'm about to do work")
	s := spinner.New(spinner.CharSets[9], 100*time.Millisecond)
	s.Prefix = "Doing the work... "
	s.Start()
	time.Sleep(2 * time.Second)
	s.Stop()
	fmt.Println("Done!")
}
예제 #4
0
파일: app.go 프로젝트: yujinqiu/spinner
func main() {
	s := spinner.New(spinner.CharSets[0], 100*time.Millisecond)
	s.Prefix = "Colors: "
	if err := s.Color("yellow"); err != nil {
		log.Fatalln(err)
	}
	s.Start()
	time.Sleep(4 * time.Second)
	if err := s.Color("red"); err != nil {
		log.Fatalln(err)
	}
	s.UpdateCharSet(spinner.CharSets[20])
	s.Reverse()
	s.Restart()
	time.Sleep(4 * time.Second)
	if err := s.Color("blue"); err != nil {
		log.Fatalln(err)
	}
	s.UpdateCharSet(spinner.CharSets[3])
	s.Restart()
	time.Sleep(4 * time.Second)
	if err := s.Color("cyan"); err != nil {
		log.Fatalln(err)
	}
	s.UpdateCharSet(spinner.CharSets[28])
	s.Reverse()
	s.Restart()
	time.Sleep(4 * time.Second)
	if err := s.Color("green"); err != nil {
		log.Fatalln(err)
	}
	s.UpdateCharSet(spinner.CharSets[25])
	s.Restart()
	time.Sleep(4 * time.Second)
	if err := s.Color("magenta"); err != nil {
		log.Fatalln(err)
	}
	s.UpdateCharSet(spinner.CharSets[32])
	s.Restart()
	time.Sleep(4 * time.Second)
	if err := s.Color("white"); err != nil {
		log.Fatalln(err)
	}
	s.UpdateCharSet(spinner.CharSets[31])
	s.Restart()
	time.Sleep(4 * time.Second)
	s.Stop()
	println("")
}
예제 #5
0
파일: stdcli.go 프로젝트: gmelika/rack
func init() {
	Binary = filepath.Base(os.Args[0])
	Exiter = os.Exit
	Querier = queryExecCommand
	Runner = runExecCommand
	Spinner = spinner.New(spinner.CharSets[9], 100*time.Millisecond)
	Tagger = tagTimeUnix
	Writer = ioutil.WriteFile

	cli.AppHelpTemplate = `{{.Name}}: {{.Usage}}

Usage:
  {{.Name}} <command> [args...]

Subcommands: ({{.Name}} help <subcommand>)
  {{range .Commands}}{{join .Names ", "}}{{ "\t" }}{{.Description}}
  {{end}}{{if .VisibleFlags}}
Options:
  {{range .VisibleFlags}}{{.}}
  {{end}}{{end}}
`

	cli.CommandHelpTemplate = fmt.Sprintf(`%s {{.FullName}}: {{.Description}}

Usage:
  %s {{.FullName}} {{.Usage}}
{{if .Subcommands}}
Subcommands: (%s {{.FullName}} help <subcommand>)
  {{range .Subcommands}}{{join .Names ", "}}{{ "\t" }}{{.Description}}
  {{end}}{{end}}{{if .VisibleFlags}}
Options:
   {{range .VisibleFlags}}{{.}}
   {{end}}{{ end }}
`, Binary, Binary, Binary)

	cli.SubcommandHelpTemplate = `{{.Name}}: {{.Usage}}

Usage:
  {{.Name}} <command> [args...]

Subcommands: ({{.Name}} help <subcommand>)
  {{range .Commands}}{{join .Names ", "}}{{ "\t" }}{{.Description}}
  {{end}}{{if .VisibleFlags}}
Options:
  {{range .VisibleFlags}}{{.}}
  {{end}}{{end}}
`
}
예제 #6
0
파일: spinner.go 프로젝트: djui/dlite
func Spin(fm Steps) error {
	for _, fn := range fm {
		s := spinner.New(spinner.CharSets[9], time.Millisecond*100)
		s.Prefix = fmt.Sprintf("%s: ", fn.Prefix)
		s.Start()
		err := fn.Action()
		s.Stop()
		if err != nil {
			fmt.Printf("\r%s: ERROR!\n", fn.Prefix)
			return err
		} else {
			fmt.Printf("\r%s: done\n", fn.Prefix)
		}
	}

	return nil
}
예제 #7
0
func Spin(fm FunctionMap) error {
	for prefix, fn := range fm {
		s := spinner.New(spinner.CharSets[9], time.Millisecond*100)
		s.Prefix = fmt.Sprintf("%s: ", prefix)
		s.Start()
		err := fn()
		s.Stop()
		if err != nil {
			fmt.Printf("\r%s: ERROR - %s\n", prefix, err)
			return err
		} else {
			fmt.Printf("\r%s: done\n", prefix)
		}
	}

	return nil
}
예제 #8
0
파일: packages.go 프로젝트: abutre/bunch
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
}
예제 #9
0
파일: app.go 프로젝트: yujinqiu/spinner
func main() {
	s := spinner.New(spinner.CharSets[9], 100*time.Millisecond) // Build our new spinner
	s.Color("red")                                              // Set the spinner color to red
	s.Start()                                                   // Start the spinner
	time.Sleep(4 * time.Second)                                 // Run for some time to simulate work

	s.UpdateCharSet(spinner.CharSets[9])  // Update spinner to use a different character set
	s.UpdateSpeed(100 * time.Millisecond) // Update the speed the spinner spins at
	s.Color("yellow")
	s.Restart() // Restart the spinner
	time.Sleep(4 * time.Second)

	s.Reverse() // Reverse the direction the spinner is spinning
	s.Color("green")
	s.Restart()
	time.Sleep(4 * time.Second)

	s.Prefix = "prefixed text: " // Prefix text before the spinner
	time.Sleep(4 * time.Second)
	s.Prefix = ""
	s.Suffix = "  :appended text" // Append text after the spinner
	time.Sleep(4 * time.Second)
	s.Stop() // Stop the spinner
}
예제 #10
0
파일: ui.go 프로젝트: nlf/dlite
func spin(prefix string, f func() error) *cli.ExitError {
	spin := spinner.New(spinner.CharSets[9], time.Millisecond*100)
	spin.Prefix = fmt.Sprintf("%s: ", prefix)
	spin.Start()
	err := f()
	spin.Stop()
	if err != nil {
		cliError, ok := err.(*cli.ExitError)
		if ok {
			if cliError.ExitCode() != 0 {
				fmt.Printf("\r%s: ERROR!\n", prefix)
				return cliError
			}

			fmt.Printf("\r%s: done\n", prefix)
			return cli.NewExitError("", 0)
		}
		fmt.Printf("\r%s: ERROR!\n", prefix)
		return cli.NewExitError(err.Error(), 1)
	}

	fmt.Printf("\r%s: done\n", prefix)
	return cli.NewExitError("", 0)
}
예제 #11
0
파일: packages.go 프로젝트: abutre/bunch
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
}
예제 #12
0
파일: packages.go 프로젝트: abutre/bunch
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
}
예제 #13
0
	"os/signal"
	"strconv"
	"syscall"
	"time"
)

//func init() {
//	listCmd.AddCommand(listDraftsCmd)
//}

type response struct {
	addr *net.IPAddr
	rtt  time.Duration
}

var spin = spinner.New(spinner.CharSets[34], 100*time.Millisecond)

var pingCmd = &cobra.Command{
	Use:   "ping",
	Short: "List top 5 servers (by latency)",
	Long:  `List all of the drafts in your content directory.`,
	PreRun: func(cmd *cobra.Command, args []string) {
		spin.Prefix = "Scanning: "
		spin.FinalMSG = "Finished..."
		spin.Color("green")
		spin.Start()
	},
	PostRun: func(cmd *cobra.Command, args []string) {
		spin.Stop()
	},
	Run: func(cmd *cobra.Command, args []string) {
예제 #14
0
파일: main.go 프로젝트: ankoh/vmlcm
func main() {
	// Create spinner
	spinner := spinner.New(spinner.CharSets[14], 100*time.Millisecond)
	spinner.Color("cyan")
	spinner.Start()

	// First read arguments
	args, argError := util.ParseArguments()
	if argError != nil {
		spinner.Stop()
		fmt.Println(argError.Error())
		return
	}

	// Then read configuration
	config, configError := util.ParseConfiguration(*args.ConfigPath)
	if configError != nil {
		spinner.Stop()
		fmt.Println(configError.Error())
		return
	}

	// Create vmrun wrapper
	var vmrun vmware.VmrunWrapper
	vmrun = vmware.NewCLIVmrun(config.Vmrun)

	// Create output buffer
	buffer := new(bytes.Buffer)

	// Switch commands
	switch args.Command {
	case util.VerifyCommand:
		err := controller.Verify(buffer, vmrun, config)
		if err != nil {
			spinner.Stop()
			fmt.Println(err.Error())
			return
		}
	case util.StatusCommand:
		if controller.Verify(nil, vmrun, config) != nil {
			spinner.Stop()
			fmt.Println("Failed to verify settings. Please run 'verify' to get more details")
			return
		}
		err := controller.Status(buffer, vmrun, config)
		if err != nil {
			spinner.Stop()
			fmt.Println(err.Error())
			return
		}
	case util.UseCommand:
		if controller.Verify(nil, vmrun, config) != nil {
			spinner.Stop()
			fmt.Println("Failed to verify settings. Please run 'verify' to get more details")
			return
		}
		err := controller.Use(buffer, vmrun, config, args.CommandIntParameter)
		if err != nil {
			spinner.Stop()
			fmt.Print(buffer.String())
			fmt.Println(err.Error())
			return
		}
	case util.StartCommand:
		if controller.Verify(nil, vmrun, config) != nil {
			spinner.Stop()
			fmt.Println("Failed to verify settings. Please run 'verify' to get more details")
			return
		}
		err := controller.Start(buffer, vmrun, config)
		if err != nil {
			spinner.Stop()
			fmt.Print(buffer.String())
			fmt.Println(err.Error())
			return
		}
	case util.StopCommand:
		if controller.Verify(nil, vmrun, config) != nil {
			spinner.Stop()
			fmt.Println("Failed to verify settings. Please run 'verify' to get more details")
			return
		}
		err := controller.Stop(buffer, vmrun, config)
		if err != nil {
			spinner.Stop()
			fmt.Print(buffer.String())
			fmt.Println(err.Error())
			return
		}
	case util.SnapshotCommand:
		if controller.Verify(nil, vmrun, config) != nil {
			spinner.Stop()
			fmt.Println("Failed to verify settings. Please run 'verify' to get more details")
			return
		}
		err := controller.Snapshot(buffer, vmrun, config)
		if err != nil {
			spinner.Stop()
			fmt.Print(buffer.String())
			fmt.Println(err.Error())
			return
		}
	}

	// Stop spinner
	spinner.Stop()

	// Print output buffer
	fmt.Print(buffer.String())
}
예제 #15
0
파일: techcrunch.go 프로젝트: umayr/goof
func NewTechCrunch() *TechCrunch {
	return &TechCrunch{page: 1, debug: debug.Debug(name), spinner: spinner.New(spinner.CharSets[14], 100*time.Millisecond)}
}