Ejemplo n.º 1
0
// MirrorsList displays a list of currently setup mirrors.
func MirrorsList() error {
	home := gpath.Home()

	op := filepath.Join(home, "mirrors.yaml")

	if _, err := os.Stat(op); os.IsNotExist(err) {
		msg.Info("No mirrors exist. No mirrors.yaml file not found")
		return nil
	}

	ov, err := mirrors.ReadMirrorsFile(op)
	if err != nil {
		msg.Die("Unable to read mirrors.yaml file: %s", err)
	}

	if len(ov.Repos) == 0 {
		msg.Info("No mirrors found")
		return nil
	}

	msg.Info("Mirrors...")
	for _, r := range ov.Repos {
		if r.Vcs == "" {
			msg.Info("--> %s replaced by %s", r.Original, r.Repo)
		} else {
			msg.Info("--> %s replaced by %s (%s)", r.Original, r.Repo, r.Vcs)
		}
	}

	return nil
}
Ejemplo n.º 2
0
Archivo: glide.go Proyecto: akutz/glide
func main() {
	app := cli.NewApp()
	app.Name = "glide"
	app.Usage = usage
	app.Version = version
	app.Flags = []cli.Flag{
		cli.StringFlag{
			Name:  "yaml, y",
			Value: "glide.yaml",
			Usage: "Set a YAML configuration file.",
		},
		cli.BoolFlag{
			Name:  "quiet, q",
			Usage: "Quiet (no info or debug messages)",
		},
		cli.BoolFlag{
			Name:  "debug",
			Usage: "Print debug verbose informational messages",
		},
		cli.StringFlag{
			Name:   "home",
			Value:  gpath.Home(),
			Usage:  "The location of Glide files",
			EnvVar: "GLIDE_HOME",
		},
		cli.StringFlag{
			Name:   "tmp",
			Value:  "",
			Usage:  "The temp directory to use. Defaults to systems temp",
			EnvVar: "GLIDE_TMP",
		},
		cli.BoolFlag{
			Name:  "no-color",
			Usage: "Turn off colored output for log messages",
		},
	}
	app.CommandNotFound = func(c *cli.Context, command string) {
		// TODO: Set some useful env vars.
		action.Plugin(command, os.Args)
	}
	app.Before = startup
	app.After = shutdown
	app.Commands = commands()

	// Detect errors from the Before and After calls and exit on them.
	if err := app.Run(os.Args); err != nil {
		msg.Err(err.Error())
		os.Exit(1)
	}

	// If there was a Error message exit non-zero.
	if msg.HasErrored() {
		m := msg.Color(msg.Red, "An Error has occurred")
		msg.Msg(m)
		os.Exit(2)
	}
}
Ejemplo n.º 3
0
// MirrorsSet sets a mirror to use
func MirrorsSet(o, r, v string) error {
	if o == "" || r == "" {
		msg.Err("Both the original and mirror values are required")
		return nil
	}

	home := gpath.Home()

	op := filepath.Join(home, "mirrors.yaml")

	var ov *mirrors.Mirrors
	if _, err := os.Stat(op); os.IsNotExist(err) {
		msg.Info("No mirrors.yaml file exists. Creating new one")
		ov = &mirrors.Mirrors{
			Repos: make(mirrors.MirrorRepos, 0),
		}
	} else {
		ov, err = mirrors.ReadMirrorsFile(op)
		if err != nil {
			msg.Die("Error reading existing mirrors.yaml file: %s", err)
		}
	}

	found := false
	for i, re := range ov.Repos {
		if re.Original == o {
			found = true
			msg.Info("%s found in mirrors. Replacing with new settings", o)
			ov.Repos[i].Repo = r
			ov.Repos[i].Vcs = v
		}
	}

	if !found {
		nr := &mirrors.MirrorRepo{
			Original: o,
			Repo:     r,
			Vcs:      v,
		}
		ov.Repos = append(ov.Repos, nr)
	}

	msg.Info("%s being set to %s", o, r)

	err := ov.WriteFile(op)
	if err != nil {
		msg.Err("Error writing mirrors.yaml file: %s", err)
	} else {
		msg.Info("mirrors.yaml written with changes")
	}

	return nil
}
Ejemplo n.º 4
0
// MirrorsRemove removes a mirrors setting
func MirrorsRemove(k string) error {
	if k == "" {
		msg.Err("The mirror to remove is required")
		return nil
	}

	home := gpath.Home()

	op := filepath.Join(home, "mirrors.yaml")

	if _, err := os.Stat(op); os.IsNotExist(err) {
		msg.Err("mirrors.yaml file not found")
		return nil
	}

	ov, err := mirrors.ReadMirrorsFile(op)
	if err != nil {
		msg.Die("Unable to read mirrors.yaml file: %s", err)
	}

	var nre mirrors.MirrorRepos
	var found bool
	for _, re := range ov.Repos {
		if re.Original != k {
			nre = append(nre, re)
		} else {
			found = true
		}
	}

	if !found {
		msg.Warn("%s was not found in mirrors", k)
	} else {
		msg.Info("%s was removed from mirrors", k)
		ov.Repos = nre

		err = ov.WriteFile(op)
		if err != nil {
			msg.Err("Error writing mirrors.yaml file: %s", err)
		} else {
			msg.Info("mirrors.yaml written with changes")
		}
	}

	return nil
}
Ejemplo n.º 5
0
// Setup creates the cache location.
func Setup() {
	setupMutex.Lock()
	defer setupMutex.Unlock()

	if isSetup {
		return
	}
	msg.Debug("Setting up the cache directory")
	pths := []string{
		"cache",
		filepath.Join("cache", "src"),
		filepath.Join("cache", "info"),
	}

	for _, l := range pths {
		err := os.MkdirAll(filepath.Join(gpath.Home(), l), 0755)
		if err != nil {
			msg.Die("Cache directory unavailable: %s", err)
		}
	}

	isSetup = true
}
Ejemplo n.º 6
0
// Load pulls the mirrors into memory
func Load() error {
	home := gpath.Home()

	op := filepath.Join(home, "mirrors.yaml")

	var ov *Mirrors
	if _, err := os.Stat(op); os.IsNotExist(err) {
		msg.Debug("No mirrors.yaml file exists")
		ov = &Mirrors{
			Repos: make(MirrorRepos, 0),
		}
		return nil
	} else if err != nil {
		ov = &Mirrors{
			Repos: make(MirrorRepos, 0),
		}
		return err
	}

	var err error
	ov, err = ReadMirrorsFile(op)
	if err != nil {
		return fmt.Errorf("Error reading existing mirrors.yaml file: %s", err)
	}

	msg.Info("Loading mirrors from mirrors.yaml file")
	for _, o := range ov.Repos {
		msg.Debug("Found mirror: %s to %s (%s)", o.Original, o.Repo, o.Vcs)
		no := &mirror{
			Repo: o.Repo,
			Vcs:  o.Vcs,
		}
		mirrors[o.Original] = no
	}

	return nil
}
Ejemplo n.º 7
0
// Setup creates the cache location.
func Setup() error {
	setupMutex.Lock()
	defer setupMutex.Unlock()

	if isSetup {
		return nil
	}
	msg.Debug("Setting up the cache directory")
	pths := []string{
		"cache",
		filepath.Join("cache", "src"),
		filepath.Join("cache", "info"),
	}

	for _, l := range pths {
		err := os.MkdirAll(filepath.Join(gpath.Home(), l), 0755)
		if err != nil {
			return err
		}
	}

	isSetup = true
	return nil
}
Ejemplo n.º 8
0
func commands() []cli.Command {
	return []cli.Command{
		{
			Name:      "create",
			ShortName: "init",
			Usage:     "Initialize a new project, creating a glide.yaml file",
			Description: `This command starts from a project without Glide and
	sets it up. It generates a glide.yaml file, parsing your codebase to guess
	the dependencies to include. Once this step is done you may edit the
	glide.yaml file to update imported dependency properties such as the version
	or version range to include.

	To fetch the dependencies you may run 'glide install'.`,
			Flags: []cli.Flag{
				cli.BoolFlag{
					Name:  "skip-import",
					Usage: "When initializing skip importing from other package managers.",
				},
			},
			Action: func(c *cli.Context) {
				action.Create(".", c.Bool("skip-import"))
			},
		},
		{
			Name:  "get",
			Usage: "Install one or more packages into `vendor/` and add dependency to glide.yaml.",
			Description: `Gets one or more package (like 'go get') and then adds that file
	to the glide.yaml file. Multiple package names can be specified on one line.

		$ glide get github.com/Masterminds/cookoo/web

	The above will install the project github.com/Masterminds/cookoo and add
	the subpackage 'web'.

	If a fetched dependency has a glide.yaml file, configuration from Godep,
	GPM, or GB Glide that configuration will be used to find the dependencies
	and versions to fetch. If those are not available the dependent packages will
	be fetched as either a version specified elsewhere or the latest version.

	When adding a new dependency Glide will perform an update to work out the
	the versions to use from the dependency tree. This will generate an updated
	glide.lock file with specific locked versions to use.
	`,
			Flags: []cli.Flag{
				cli.BoolFlag{
					Name:  "insecure",
					Usage: "Use http:// rather than https:// to retrieve pacakges.",
				},
				cli.BoolFlag{
					Name:  "no-recursive, quick",
					Usage: "Disable updating dependencies' dependencies.",
				},
				cli.BoolFlag{
					Name:  "force",
					Usage: "If there was a change in the repo or VCS switch to new one. Warning, changes will be lost.",
				},
				cli.BoolFlag{
					Name:  "all-dependencies",
					Usage: "This will resolve all dependencies for all packages, not just those directly used.",
				},
				cli.BoolFlag{
					Name:  "update-vendored, u",
					Usage: "Update vendored packages (without local VCS repo). Warning, changes will be lost.",
				},
				cli.BoolFlag{
					Name:  "cache",
					Usage: "When downloading dependencies attempt to cache them.",
				},
				cli.BoolFlag{
					Name:  "cache-gopath",
					Usage: "When downloading dependencies attempt to put them in the GOPATH, too.",
				},
				cli.BoolFlag{
					Name:  "use-gopath",
					Usage: "Copy dependencies from the GOPATH if they exist there.",
				},
			},
			Action: func(c *cli.Context) {
				if len(c.Args()) < 1 {
					fmt.Println("Oops! Package name is required.")
					os.Exit(1)
				}

				inst := &repo.Installer{
					Force:           c.Bool("force"),
					UseCache:        c.Bool("cache"),
					UseGopath:       c.Bool("use-gopath"),
					UseCacheGopath:  c.Bool("cache-gopath"),
					UpdateVendored:  c.Bool("update-vendored"),
					ResolveAllFiles: c.Bool("all-dependencies"),
				}
				packages := []string(c.Args())
				insecure := c.Bool("insecure")
				action.Get(packages, inst, insecure, c.Bool("no-recursive"))
			},
		},
		{
			Name:      "remove",
			ShortName: "rm",
			Usage:     "Remove a package from the glide.yaml file, and regenerate the lock file.",
			Description: `This takes one or more package names, and removes references from the glide.yaml file.
	This will rebuild the glide lock file with the following constraints:

	- Dependencies are re-negotiated. Any that are no longer used are left out of the lock.
	- Minor version re-nogotiation is performed on remaining dependencies.
	- No updates are peformed. You may want to run 'glide up' to accomplish that.
`,
			Flags: []cli.Flag{
				cli.BoolFlag{
					Name:  "delete,d",
					Usage: "Also delete from vendor/ any packages that are no longer used.",
				},
			},
			Action: func(c *cli.Context) {
				if len(c.Args()) < 1 {
					fmt.Println("Oops! At least one package name is required.")
					os.Exit(1)
				}

				if c.Bool("delete") {
					// FIXME: Implement this in the installer.
					fmt.Println("Delete is not currently implemented.")
				}

				inst := &repo.Installer{
					Force: c.Bool("force"),
				}
				packages := []string(c.Args())
				action.Remove(packages, inst)
			},
		},
		{
			Name:  "import",
			Usage: "Import files from other dependency management systems.",
			Subcommands: []cli.Command{
				{
					Name:  "godep",
					Usage: "Import Godep's Godeps.json files and display the would-be yaml file",
					Flags: []cli.Flag{
						cli.StringFlag{
							Name:  "file, f",
							Usage: "Save all of the discovered dependencies to a Glide YAML file.",
						},
					},
					Action: func(c *cli.Context) {
						action.ImportGodep(c.String("file"))
					},
				},
				{
					Name:  "gpm",
					Usage: "Import GPM's Godeps and Godeps-Git files and display the would-be yaml file",
					Flags: []cli.Flag{
						cli.StringFlag{
							Name:  "file, f",
							Usage: "Save all of the discovered dependencies to a Glide YAML file.",
						},
					},
					Action: func(c *cli.Context) {
						action.ImportGPM(c.String("file"))
					},
				},
				{
					Name:  "gb",
					Usage: "Import gb's manifest file and display the would-be yaml file",
					Flags: []cli.Flag{
						cli.StringFlag{
							Name:  "file, f",
							Usage: "Save all of the discovered dependencies to a Glide YAML file.",
						},
					},
					Action: func(c *cli.Context) {
						action.ImportGB(c.String("file"))
					},
				},
			},
		},
		{
			Name:        "name",
			Usage:       "Print the name of this project.",
			Description: `Read the glide.yaml file and print the name given on the 'package' line.`,
			Action: func(c *cli.Context) {
				action.Name()
			},
		},
		{
			Name:      "novendor",
			ShortName: "nv",
			Usage:     "List all non-vendor paths in a directory.",
			Description: `Given a directory, list all the relevant Go paths that are not vendored.

Example:

			$ go test $(glide novendor)
`,
			Flags: []cli.Flag{
				cli.StringFlag{
					Name:  "dir,d",
					Usage: "Specify a directory to run novendor against.",
					Value: ".",
				},
				cli.BoolFlag{
					Name:  "no-subdir,x",
					Usage: "Specify this to prevent nv from append '/...' to all directories.",
				},
			},
			Action: func(c *cli.Context) {
				action.NoVendor(c.String("dir"), true, !c.Bool("no-subdir"))
			},
		},
		{
			Name:  "rebuild",
			Usage: "Rebuild ('go build') the dependencies",
			Description: `This rebuilds the packages' '.a' files. On some systems
	this can improve performance on subsequent 'go run' and 'go build' calls.`,
			Action: func(c *cli.Context) {
				action.Rebuild()
			},
		},
		{
			Name:      "install",
			ShortName: "i",
			Usage:     "Install a project's dependencies",
			Description: `This uses the native VCS of each packages to install
		the appropriate version. There are two ways a projects dependencies can
	be installed. When there is a glide.yaml file defining the dependencies but
	no lock file (glide.lock) the dependencies are installed using the "update"
	command and a glide.lock file is generated pinning all dependencies. If a
	glide.lock file is already present the dependencies are installed or updated
	from the lock file.`,
			Flags: []cli.Flag{
				cli.BoolFlag{
					Name:  "delete",
					Usage: "Delete vendor packages not specified in config.",
				},
				cli.BoolFlag{
					Name:  "force",
					Usage: "If there was a change in the repo or VCS switch to new one. Warning: changes will be lost.",
				},
				cli.BoolFlag{
					Name:  "update-vendored, u",
					Usage: "Update vendored packages (without local VCS repo). Warning: this may destroy local modifications to vendor/.",
				},
				cli.StringFlag{
					Name:  "file, f",
					Usage: "Save all of the discovered dependencies to a Glide YAML file. (DEPRECATED: This has no impact.)",
				},
				cli.BoolFlag{
					Name:  "cache",
					Usage: "When downloading dependencies attempt to cache them.",
				},
				cli.BoolFlag{
					Name:  "cache-gopath",
					Usage: "When downloading dependencies attempt to put them in the GOPATH, too.",
				},
				cli.BoolFlag{
					Name:  "use-gopath",
					Usage: "Copy dependencies from the GOPATH if they exist there.",
				},
			},
			Action: func(c *cli.Context) {
				installer := &repo.Installer{
					DeleteUnused:   c.Bool("deleteOptIn"),
					UpdateVendored: c.Bool("update-vendored"),
					Force:          c.Bool("force"),
					UseCache:       c.Bool("cache"),
					UseCacheGopath: c.Bool("cache-gopath"),
					UseGopath:      c.Bool("use-gopath"),
					Home:           gpath.Home(),
				}

				action.Install(installer)
			},
		},
		{
			Name:      "update",
			ShortName: "up",
			Usage:     "Update a project's dependencies",
			Description: `This uses the native VCS of each package to try to
	pull the most applicable updates. Packages with fixed refs (Versions or
	tags) will not be updated. Packages with no ref or with a branch ref will
	be updated as expected.

	If a dependency has a glide.yaml file, update will read that file and
	update those dependencies accordingly. Those dependencies are maintained in
	a the top level 'vendor/' directory. 'vendor/foo/bar' will have its
	dependencies stored in 'vendor/'. This behavior can be disabled with
	'--no-recursive'. When this behavior is skipped a glide.lock file is not
	generated because the full dependency tree cannot be known.

	Glide will also import Godep, GB, and GPM files as it finds them in dependencies.
	It will create a glide.yaml file from the Godeps data, and then update. This
	has no effect if '--no-recursive' is set.

	If the '--update-vendored' flag (aliased to '-u') is present vendored
	dependencies, stored in your projects VCS repository, will be updated. This
	works by removing the old package, checking out an the repo and setting the
	version, and removing the VCS directory.

	By default, packages that are discovered are considered transient, and are
	not stored in the glide.yaml file. The --file=NAME.yaml flag allows you
	to save the discovered dependencies to a YAML file.
	`,
			Flags: []cli.Flag{
				cli.BoolFlag{
					Name:  "delete",
					Usage: "Delete vendor packages not specified in config.",
				},
				cli.BoolFlag{
					Name:  "no-recursive, quick",
					Usage: "Disable updating dependencies' dependencies. Only update things in glide.yaml.",
				},
				cli.BoolFlag{
					Name:  "force",
					Usage: "If there was a change in the repo or VCS switch to new one. Warning, changes will be lost.",
				},
				cli.BoolFlag{
					Name:  "all-dependencies",
					Usage: "This will resolve all dependencies for all packages, not just those directly used.",
				},
				cli.BoolFlag{
					Name:  "update-vendored, u",
					Usage: "Update vendored packages (without local VCS repo). Warning, changes will be lost.",
				},
				cli.StringFlag{
					Name:  "file, f",
					Usage: "Save all of the discovered dependencies to a Glide YAML file.",
				},
				cli.BoolFlag{
					Name:  "cache",
					Usage: "When downloading dependencies attempt to cache them.",
				},
				cli.BoolFlag{
					Name:  "cache-gopath",
					Usage: "When downloading dependencies attempt to put them in the GOPATH, too.",
				},
				cli.BoolFlag{
					Name:  "use-gopath",
					Usage: "Copy dependencies from the GOPATH if they exist there.",
				},
			},
			Action: func(c *cli.Context) {
				installer := &repo.Installer{
					DeleteUnused:    c.Bool("deleteOptIn"),
					UpdateVendored:  c.Bool("update-vendored"),
					ResolveAllFiles: c.Bool("all-dependencies"),
					Force:           c.Bool("force"),
					UseCache:        c.Bool("cache"),
					UseCacheGopath:  c.Bool("cache-gopath"),
					UseGopath:       c.Bool("use-gopath"),
					Home:            gpath.Home(),
				}

				action.Update(installer, c.Bool("no-recursive"))
			},
		},
		{
			Name:  "tree",
			Usage: "Tree prints the dependencies of this project as a tree.",
			Description: `This scans a project's source files and builds a tree
	representation of the import graph.

	It ignores testdata/ and directories that begin with . or _. Packages in
	vendor/ are only included if they are referenced by the main project or
	one of its dependencies.`,
			Action: func(c *cli.Context) {
				action.Tree(".", false)
			},
		},
		{
			Name:  "list",
			Usage: "List prints all dependencies that the present code references.",
			Description: `List scans your code and lists all of the packages that are used.

			It does not use the glide.yaml. Instead, it inspects the code to determine what packages are
			imported.

			Directories that begin with . or _ are ignored, as are testdata directories. Packages in
			vendor are only included if they are used by the project.
			`,
			Action: func(c *cli.Context) {
				action.List(".", true)
			},
		},
		{
			Name:  "about",
			Usage: "Learn about Glide",
			Action: func(c *cli.Context) {
				action.About()
			},
		},
	}
}
Ejemplo n.º 9
0
// SystemUnlock removes the system wide Glide cache lock.
func SystemUnlock() {
	lockdone <- struct{}{}
	os.Remove(lockFileName)
}

var lockdone = make(chan struct{}, 1)

type lockdata struct {
	Comment string `json:"comment"`
	Pid     int    `json:"pid"`
	Time    string `json:"time"`
}

var lockFileName = filepath.Join(gpath.Home(), "lock.json")

// Write a lock for now.
func writeLock() error {

	// If the lock should not be written exit immediately. This happens in cases
	// where shutdown/clean is happening.
	if !shouldWriteLock {
		return nil
	}

	ld := &lockdata{
		Comment: "File managed by Glide (https://glide.sh)",
		Pid:     os.Getpid(),
		Time:    time.Now().Format(time.RFC3339Nano),
	}
Ejemplo n.º 10
0
// Location returns the location of the cache.
func Location() (string, error) {
	p := filepath.Join(gpath.Home(), "cache")
	err := Setup()

	return p, err
}
Ejemplo n.º 11
0
// Location returns the location of the cache.
func Location() string {
	p := filepath.Join(gpath.Home(), "cache")
	Setup()

	return p
}