glide

glide

项目地址

下面可能是从 github 的 readme 中翻译的。git

原理

扫描项目或库的源码来检测须要的依赖。为了检测版本和位置,Glide须要一个glide.yaml文件。 依赖的包会统计imports来扫描它的依赖。若是依赖的项目也包含glide.yaml文件,将使用该文件帮助检测依赖规则。Godep, GB, GOM, GPM的配置也导进来了。 依赖会被导出到vendor/目录,这样go工具可以找到并使用它们。 glide.lock文件中包含全部的依赖,包括依赖的依赖。 glide init命令用来设置一个新项目。glide update经过扫描和规则从新生成依赖版本。glide install会安装列举在glide.lock中的版本而不进行扫描,除非glide.lock文件没找到。github

安装

在 Mac 或者 Linux 上最简单的安装最新版的脚本是:web

curl https://glide.sh/get | sh

在 Mac 上也能够经过 Homebrew 安装:编程

$ brew install glide

在 Ubuntu Precise(12.04), Trusty (14.04), Wily (15.10) 或 Xenial (16.04) 上:bash

sudo add-apt-repository ppa:masterminds/glide && sudo apt-get update
sudo apt-get install glide

二进制包 适用于 Mac, Linux, Windows。curl

开发版经过 go get github.com/Masterminds/glide 得到源码。ide

使用

$ glide create                            # Start a new workspace
$ open glide.yaml                         # and edit away!
$ glide get github.com/Masterminds/cookoo # Get a package and add to glide.yaml
$ glide install                           # Install packages and dependencies
# work, work, work
$ go build                                # Go tools work normally
$ glide up                                # Update to newest versions of the package

glide create(又名init)

初始化一个新的工做区。建立一个glide.yaml文件并写入猜想的包和版本。例如,若是你的项目用的是Godep,那就用Godep指定的版本。Glide足够聪明,可以扫描你的代码库并检测导入的包,无论你是否是用其余包管理工具指定的。工具

$ glide create
[INFO]	Generating a YAML configuration file and guessing the dependencies
[INFO]	Attempting to import from other package managers (use --skip-import to skip)
[INFO]	Scanning code to look for dependencies
[INFO]	--> Found reference to github.com/Masterminds/semver
[INFO]	--> Found reference to github.com/Masterminds/vcs
[INFO]	--> Found reference to github.com/codegangsta/cli
[INFO]	--> Found reference to gopkg.in/yaml.v2
[INFO]	Writing configuration file (glide.yaml)
[INFO]	Would you like Glide to help you find ways to improve your glide.yaml configuration?
[INFO]	If you want to revisit this step you can use the config-wizard command at any time.
[INFO]	Yes (Y) or No (N)?
n
[INFO]	You can now edit the glide.yaml file. Consider:
[INFO]	--> Using versions and ranges. See https://glide.sh/docs/versions/
[INFO]	--> Adding additional metadata. See https://glide.sh/docs/glide.yaml/
[INFO]	--> Running the config-wizard command to improve the versions in your configuration

这里说的 config-wizard(配置向导)能够如今运行,也能够之后运行,它能帮助你指出你可使用的依赖包的版本范围。测试

glide config-wizard

这个命令运行一个向导,它会扫描你的依赖并从中检索信息,提出建议,你能够交互式的选择。例如,它能够发现一个依赖包使用了语义版本,你能够选择要使用的版本范围。ui

glide get [package name]

你能够经过 glide get 下载一个或多个包到你的 vendor 目录,并添加到你的 glide.yaml 文件中:

glide get github.com/Masterminds/cookoo

这个命令会深刻列出的包并经过Godep, GPM, Gom, 和 GB 的配置文件获取它的依赖。 能够在get时指定版本或分支或版本范围:

glide get github.com/a/b#master
glide get github.com/a/b#^1.2.3

关于版本号的说明能够参考:https://glide.readthedocs.io/en/latest/versions/

glide update(又名up)

下载或更新全部列在 glide.yaml 文件中的库,并放到 vendor 目录下。它会递归遍历依赖的包并拉取所须要的和从配置中读取的任何东西。

$ glide up

它会递归遍历其余包,从中寻找使用Glide, Godep, gb, gom, 和 GPM 管理的其余项目,一旦找到,这些包将会按需安装。 当依赖使用了特定的版本时, glide.lock 文件会被建立或更新。例如,若是在 glide.yaml 中一个版本号使用的是一个范围(好比 ^1.2.3),那么在 glide.lock 中就会被设置为特定的 commit id。这容许可重现的安装(见 glide install)。 从拉取的包中移除任何递归的 vendor 目录的话见 -v 标记。

glide install

当你想从 glide.lock 文件中安装指定版本时,使用 glide install

$ glide install

这会读取 glide.lock 文件,而后安装 commit id 指定的版本。 当 glide.lockglide.yaml 不一样步时,好比有一个更改,这个命令会发出警告。 更改依赖树时,运行 glide up 会重建 glide.lock 文件。 若是没有 glide.lock 文件,那么 glide install 会表现的像 update,生成一个 lock 文件。 从拉取的包中移除任何递归的 vendor 目录的话见 -v 标记。

glide novendor (别名 nv)

当你运行 go test ./... 这样的命令时它会遍历全部的子目录包括 vendor。你可能只想测试你本身的项目,而不是依赖的项目。这就是 novendor 的意义所在,它能够列举出除了 vendor 的其余全部目录。

$ go test $(glide novendor)

这个命令能够在你项目的全部目录上运行 go test 除了 vendor 目录。

glide name

当你使用glide进行脚本编程时,有种场景是你须要知道你工做的包的名称。glide name 返回列举在 glide.yaml中的包名。

glide tree

Glide 中包含一些检查代码并给出导入详情的命令,glide tree 就是其中之一,运行它给出的数据像这样:

$ glide tree
github.com/Masterminds/glide
	github.com/Masterminds/cookoo   (/Users/mfarina/Code/go/src/github.com/Masterminds/glide/vendor/github.com/Masterminds/cookoo)
		github.com/Masterminds/cookoo/io   (/Users/mfarina/Code/go/src/github.com/Masterminds/glide/vendor/github.com/Masterminds/cookoo/io)
	github.com/Masterminds/glide/cmd   (/Users/mfarina/Code/go/src/github.com/Masterminds/glide/cmd)
		github.com/Masterminds/cookoo   (/Users/mfarina/Code/go/src/github.com/Masterminds/glide/vendor/github.com/Masterminds/cookoo)
			github.com/Masterminds/cookoo/io   (/Users/mfarina/Code/go/src/github.com/Masterminds/glide/vendor/github.com/Masterminds/cookoo/io)
		github.com/Masterminds/glide/gb   (/Users/mfarina/Code/go/src/github.com/Masterminds/glide/gb)
		github.com/Masterminds/glide/util   (/Users/mfarina/Code/go/src/github.com/Masterminds/glide/util)
			github.com/Masterminds/vcs   (/Users/mfarina/Code/go/src/github.com/Masterminds/glide/vendor/github.com/Masterminds/vcs)
		github.com/Masterminds/glide/yaml   (/Users/mfarina/Code/go/src/github.com/Masterminds/glide/yaml)
			github.com/Masterminds/glide/util   (/Users/mfarina/Code/go/src/github.com/Masterminds/glide/util)
				github.com/Masterminds/vcs   (/Users/mfarina/Code/go/src/github.com/Masterminds/glide/vendor/github.com/Masterminds/vcs)
			github.com/Masterminds/vcs   (/Users/mfarina/Code/go/src/github.com/Masterminds/glide/vendor/github.com/Masterminds/vcs)
			gopkg.in/yaml.v2   (/Users/mfarina/Code/go/src/gopkg.in/yaml.v2)
		github.com/Masterminds/semver   (/Users/mfarina/Code/go/src/github.com/Masterminds/glide/vendor/github.com/Masterminds/semver)
		github.com/Masterminds/vcs   (/Users/mfarina/Code/go/src/github.com/Masterminds/glide/vendor/github.com/Masterminds/vcs)
		github.com/codegangsta/cli   (/Users/mfarina/Code/go/src/github.com/Masterminds/glide/vendor/github.com/codegangsta/cli)
	github.com/codegangsta/cli   (/Users/mfarina/Code/go/src/github.com/Masterminds/glide/vendor/github.com/codegangsta/cli)
	github.com/Masterminds/cookoo   (/Users/mfarina/Code/go/src/github.com/Masterminds/glide/vendor/github.com/Masterminds/cookoo)
		github.com/Masterminds/cookoo/io   (/Users/mfarina/Code/go/src/github.com/Masterminds/glide/vendor/github.com/Masterminds/cookoo/io)
	github.com/Masterminds/glide/gb   (/Users/mfarina/Code/go/src/github.com/Masterminds/glide/gb)
	github.com/Masterminds/glide/util   (/Users/mfarina/Code/go/src/github.com/Masterminds/glide/util)
		github.com/Masterminds/vcs   (/Users/mfarina/Code/go/src/github.com/Masterminds/glide/vendor/github.com/Masterminds/vcs)
	github.com/Masterminds/glide/yaml   (/Users/mfarina/Code/go/src/github.com/Masterminds/glide/yaml)
		github.com/Masterminds/glide/util   (/Users/mfarina/Code/go/src/github.com/Masterminds/glide/util)
			github.com/Masterminds/vcs   (/Users/mfarina/Code/go/src/github.com/Masterminds/glide/vendor/github.com/Masterminds/vcs)
		github.com/Masterminds/vcs   (/Users/mfarina/Code/go/src/github.com/Masterminds/glide/vendor/github.com/Masterminds/vcs)
		gopkg.in/yaml.v2   (/Users/mfarina/Code/go/src/gopkg.in/yaml.v2)
	github.com/Masterminds/semver   (/Users/mfarina/Code/go/src/github.com/Masterminds/glide/vendor/github.com/Masterminds/semver)
	github.com/Masterminds/vcs   (/Users/mfarina/Code/go/src/github.com/Masterminds/glide/vendor/github.com/Masterminds/vcs)
	github.com/codegangsta/cli   (/Users/mfarina/Code/go/src/github.com/Masterminds/glide/vendor/github.com/codegangsta/cli)

它展现了一颗导入树,不包括核心库。 这个命令被废弃了,不久会删除

glide list

这个命令会展现项目导入的全部包的列表,以字母顺序。

$ glide list
INSTALLED packages:
	vendor/github.com/Masterminds/cookoo
	vendor/github.com/Masterminds/cookoo/fmt
	vendor/github.com/Masterminds/cookoo/io
	vendor/github.com/Masterminds/cookoo/web
	vendor/github.com/Masterminds/semver
	vendor/github.com/Masterminds/vcs
	vendor/github.com/codegangsta/cli
	vendor/gopkg.in/yaml.v2

glide help

打印帮助信息。

$ glide help

glide --version

打印版本信息。

$ glide --version
glide version 0.12.0

glide.yaml

详细文档见 https://glide.sh/docs/glide.yaml

相关文章
相关标签/搜索