Usage:
- go get [-d] [-fix] [-u] [build flags] [packages]
+ go get [-d] [-fix] [-t] [-u] [build flags] [packages]
Get downloads and installs the packages named by the import paths,
along with their dependencies.
The -fix flag instructs get to run the fix tool on the downloaded packages
before resolving dependencies or building the code.
+The -t flag instructs get to also download the packages required to build
+the tests for the specified packages.
+
The -u flag instructs get to use the network to update the named packages
and their dependencies. By default, get uses the network to check out
missing packages but does not use it to look for updates to existing packages.
)
var cmdGet = &Command{
- UsageLine: "get [-d] [-fix] [-u] [build flags] [packages]",
+ UsageLine: "get [-d] [-fix] [-t] [-u] [build flags] [packages]",
Short: "download and install packages and dependencies",
Long: `
Get downloads and installs the packages named by the import paths,
The -fix flag instructs get to run the fix tool on the downloaded packages
before resolving dependencies or building the code.
+The -t flag instructs get to also download the packages required to build
+the tests for the specified packages.
+
The -u flag instructs get to use the network to update the named packages
and their dependencies. By default, get uses the network to check out
missing packages but does not use it to look for updates to existing packages.
}
var getD = cmdGet.Flag.Bool("d", false, "")
+var getT = cmdGet.Flag.Bool("t", false, "")
var getU = cmdGet.Flag.Bool("u", false, "")
var getFix = cmdGet.Flag.Bool("fix", false, "")
// Phase 1. Download/update.
var stk importStack
for _, arg := range downloadPaths(args) {
- download(arg, &stk)
+ download(arg, &stk, *getT)
}
exitIfErrors()
// download runs the download half of the get command
// for the package named by the argument.
-func download(arg string, stk *importStack) {
+func download(arg string, stk *importStack, getTestDeps bool) {
p := loadPackage(arg, stk)
// There's nothing to do if this is a package in the standard library.
// Process dependencies, now that we know what they are.
for _, dep := range p.deps {
- download(dep.ImportPath, stk)
+ // Don't get test dependencies recursively.
+ download(dep.ImportPath, stk, false)
+ }
+ if getTestDeps {
+ // Process test dependencies when -t is specified.
+ // (Don't get test dependencies for test dependencies.)
+ for _, path := range p.TestImports {
+ download(path, stk, false)
+ }
+ for _, path := range p.XTestImports {
+ download(path, stk, false)
+ }
}
}
}