Пример #1
0
func New(runner command_runner.CommandRunner) (*Fetcher, error) {
	gopath, err := gopath.InstallationDirectory(os.Getenv("GOPATH"))
	if err != nil {
		return nil, err
	}

	return &Fetcher{
		runner: runner,
		gopath: gopath,

		fetchedDependencies: make(map[string]dependency.Dependency),
	}, nil
}
Пример #2
0
func main() {
	flag.Parse()

	args := flag.Args()

	command := ""

	gopath, err := gopath.InstallationDirectory(os.Getenv("GOPATH"))
	if err != nil {
		fatal("GOPATH is not set.")
	}

	GOPATH = gopath

	if len(args) == 0 {
		command = "install"
	} else {
		command = args[0]
	}

	if *showHelp || command == "help" {
		help()
		return
	}

	if *showVersion || command == "version" {
		version()
		return
	}

	if command == "install" {
		install(".", *recursive, strings.Split(*exclude, ","))
		return
	}

	if command == "check" {
		check(".")
		return
	}

	unknownCommand()
}
Пример #3
0
package gopath_test

import (
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"

	"github.com/vito/gocart/gopath"
)

var _ = Describe("GOPATH parsing", func() {
	Context("when the GOPATH is empty", func() {
		It("raises an error", func() {
			_, err := gopath.InstallationDirectory("")
			Expect(err).To(Equal(gopath.GoPathNotSet))
		})
	})

	Context("when the GOPATH has a single element", func() {
		It("returns that single element", func() {
			path, err := gopath.InstallationDirectory("/it/is/a/real/path/honest")
			Expect(err).NotTo(HaveOccurred())
			Expect(path).To(Equal("/it/is/a/real/path/honest"))
		})
	})

	Context("when the GOPATH has many elements", func() {
		It("returns the first element", func() {
			path, err := gopath.InstallationDirectory("/this/is/a/real/path/too:/it/is/a/real/path/honest")
			Expect(err).NotTo(HaveOccurred())
			Expect(path).To(Equal("/this/is/a/real/path/too"))
		})
Пример #4
0
	})

	Describe("Fetch", func() {
		It("go gets, updates, checkouts, and returns the fetched dependency", func() {
			runner.WhenRunning(fake_command_runner.CommandSpec{
				Path: exec.Command("git").Path,
				Args: []string{"rev-parse", "HEAD"},
			}, func(cmd *exec.Cmd) error {
				cmd.Stdout.Write([]byte("some-sha\n"))
				return nil
			})

			dep, err := fetcher.Fetch(dependency)
			Expect(err).ToNot(HaveOccurred())

			gopath, _ := gopath.InstallationDirectory(os.Getenv("GOPATH"))

			Ω(runner).Should(HaveExecutedSerially(
				fake_command_runner.CommandSpec{
					Path: exec.Command("go").Path,
					Args: []string{"get", "-d", "-v", dependency.Path},
				},
				fake_command_runner.CommandSpec{
					Path: exec.Command("git").Path,
					Args: []string{"fetch"},
					Dir:  dependency.FullPath(gopath),
				},
				fake_command_runner.CommandSpec{
					Path: exec.Command("git").Path,
					Args: []string{"checkout", "v1.2"},
					Dir:  dependency.FullPath(gopath),