}
var out []string
for _, a := range args {
- if (strings.HasPrefix(a, "./") || strings.HasPrefix(a, "../")) && strings.Contains(a, "...") {
+ if isLocalPath(a) && strings.Contains(a, "...") {
out = append(out, allPackagesInFS(a)...)
continue
}
}
}
+func runOut(cmdargs ...interface{}) []byte {
+ cmdline := stringList(cmdargs...)
+ out, err := exec.Command(cmdline[0], cmdline[1:]...).CombinedOutput()
+ if err != nil {
+ os.Stderr.Write(out)
+ errorf("%v", err)
+ out = nil
+ }
+ return out
+}
+
// matchPattern(pattern)(name) reports whether
// name matches pattern. Pattern is a limited glob
// pattern in which '...' means 'any string' and there
}
return x
}
+
+// isLocalPath returns true if arg is an import path denoting
+// a local file system directory. That is, it returns true if the
+// path begins with ./ or ../ .
+func isLocalPath(arg string) bool {
+ return arg == "." || arg == ".." || strings.HasPrefix(arg, "./") || strings.HasPrefix(arg, "../")
+}
t, importPath, err := build.FindTree(arg)
dir := ""
// Maybe it is a standard command.
- if err != nil && !filepath.IsAbs(arg) && strings.HasPrefix(arg, "cmd/") {
+ if err != nil && strings.HasPrefix(arg, "cmd/") {
goroot := build.Path[0]
p := filepath.Join(goroot.Path, "src", arg)
if st, err1 := os.Stat(p); err1 == nil && st.IsDir() {
err = nil
}
}
+ // Maybe it is a path to a standard command.
+ if err != nil && (filepath.IsAbs(arg) || isLocalPath(arg)) {
+ arg, _ := filepath.Abs(arg)
+ goroot := build.Path[0]
+ cmd := filepath.Join(goroot.Path, "src", "cmd") + string(filepath.Separator)
+ if st, err1 := os.Stat(arg); err1 == nil && st.IsDir() && strings.HasPrefix(arg, cmd) {
+ t = goroot
+ importPath = filepath.FromSlash(arg[len(cmd):])
+ dir = arg
+ err = nil
+ }
+ }
+
if err != nil {
return nil, err
}