Exemple #1
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)
			}
		}
	}
}
Exemple #2
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
	}
}