Exemplo n.º 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")
	}

}
Exemplo n.º 2
0
func initC(cmd *cobra.Command, args []string) {
	p := pkg.Package{
		Version: "1.0.0",
		Scripts: map[string]string{
			"setup": "echo hello world",
		},
		RawDependencies: make(map[string]string),
	}

	fmt.Printf("What is the name of your package?: ")
	_, err := fmt.Scanln(&p.Name)
	if err != nil {
		fmt.Printf(" [\033[0;31mERR\033[0m]\n")
		fmt.Printf("\t  \033[0;31m%s\033[0m\n", err)
	}

	err = pkg.WriteCaddyJSON(&p)
	if err != nil {
		fmt.Printf(" [\033[0;31mERR\033[0m]\n")
		fmt.Printf("\t  \033[0;31m%s\033[0m\n", err)
	}
}