Ejemplo n.º 1
0
func run(cmd *cobra.Command, args []string) {
	p, err := pkg.ReadCaddyJSON()
	if err != nil {
		log.Fatal(err)
		return
	}

	if script, ok := p.Scripts[args[0]]; ok {
		fmt.Printf("Running script \"%s\"\n%s\n", args[0], script)
		fields := strings.Fields(script)

		cmd := exec.Command(fields[0], fields[1:]...)
		cmd.Env = append(os.Environ(), "GO15VENDOREXPERIMENT=1")
		var buf bytes.Buffer
		cmd.Stderr = &buf
		cmd.Stdout = &buf
		err := cmd.Run()
		out := buf.String()
		fmt.Println(out)
		if err != nil {
			fmt.Println(err)
		}
		return
	}
}
Ejemplo n.º 2
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")
	}

}
Ejemplo n.º 3
0
func build(cmd *cobra.Command, args []string) {
	p, err := pkg.ReadCaddyJSON()
	if err != nil {
		log.Fatal(err)
		return
	}

	if build, ok := p.Scripts["build"]; ok {
		fmt.Printf("Running script \"build\"\n%s", build)
		fields := strings.Fields(build)

		cmd := exec.Command(fields[0], fields[1:]...)
		cmd.Env = append(os.Environ(), "GO15VENDOREXPERIMENT=1")
		var buf bytes.Buffer
		cmd.Stderr = &buf
		cmd.Stdout = &buf
		err := cmd.Run()
		out := buf.String()
		fmt.Println(out)
		if err != nil {
			fmt.Println(err)
		}
	} else {
		if strings.Contains(runtime.Version(), "go1.5") {
			// add GO15VENDOREXPERIMENT=1 env var so it uses local "vendor""
			var goArgs []string

			if output != "" {
				goArgs = []string{"-o", output}
			}

			goArgs = append(goArgs, args...)
			goArgs = append([]string{"build"}, goArgs...)

			cmd := exec.Command("go", goArgs...)
			cmd.Env = append(os.Environ(), "GO15VENDOREXPERIMENT=1")
			var buf bytes.Buffer
			cmd.Stderr = &buf
			cmd.Stdout = &buf
			err := cmd.Run()
			out := buf.String()
			fmt.Println(out)
			if err != nil {
				fmt.Println(err)
			}
		}
	}
}