1 Star 0 Fork 0

zhuchance / kubernetes

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
get.go 2.01 KB
一键复制 编辑 原始数据 按行查看 历史
package main
import (
"log"
"os"
"os/exec"
)
var cmdGet = &Command{
Name: "get",
Args: "[-t] [packages]",
Short: "download and install packages with specified dependencies",
Long: `
Get downloads to GOPATH the packages named by the import paths, and installs
them with the dependencies specified in their Godeps files.
If any of the packages do not have Godeps files, those are installed
as if by go get.
If -t is given, dependencies of test files are also downloaded and installed.
For more about specifying packages, see 'go help packages'.
`,
Run: runGet,
OnlyInGOPATH: true,
}
var getT bool
func init() {
cmdGet.Flag.BoolVar(&getT, "t", false, "get test dependencies")
}
func runGet(cmd *Command, args []string) {
if len(args) == 0 {
args = []string{"."}
}
cmdArgs := []interface{}{"get", "-d"}
if verbose {
cmdArgs = append(cmdArgs, "-v")
}
if getT {
cmdArgs = append(cmdArgs, "-t")
}
err := command("go", append(cmdArgs, args)...).Run()
if err != nil {
log.Fatalln(err)
}
// group import paths by Godeps location
groups := make(map[string][]string)
ps, err := LoadPackages(args...)
if err != nil {
log.Fatalln(err)
}
for _, pkg := range ps {
if pkg.Error.Err != "" {
log.Fatalln(pkg.Error.Err)
}
dir, _ := findInParents(pkg.Dir, "Godeps")
groups[dir] = append(groups[dir], pkg.ImportPath)
}
for dir, packages := range groups {
var c *exec.Cmd
if dir == "" {
c = command("go", "install", packages)
} else {
c = command("godep", "go", "install", packages)
c.Dir = dir
}
if err := c.Run(); err != nil {
log.Fatalln(err)
}
}
}
// command is like exec.Command, but the returned
// Cmd inherits stderr from the current process, and
// elements of args may be either string or []string.
func command(name string, args ...interface{}) *exec.Cmd {
var a []string
for _, arg := range args {
switch v := arg.(type) {
case string:
a = append(a, v)
case []string:
a = append(a, v...)
}
}
c := exec.Command(name, a...)
c.Stderr = os.Stderr
return c
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/meoom/kubernetes.git
git@gitee.com:meoom/kubernetes.git
meoom
kubernetes
kubernetes
v1.14.2-beta.0

搜索帮助

344bd9b3 5694891 D2dac590 5694891