Created
December 16, 2019 20:13
-
-
Save spagettikod/a1682a3cafbb86f0d9642fdda61c940a to your computer and use it in GitHub Desktop.
Resolve the VCS repository URL for a Go import
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"flag" | |
"fmt" | |
"log" | |
"os" | |
"golang.org/x/tools/go/vcs" | |
) | |
func usage() { | |
fmt.Printf("usage: resolveimport <import>\n\n") | |
fmt.Printf("Resolves the download VCS repository URL for a Go import\n") | |
os.Exit(1) | |
} | |
func main() { | |
flag.Parse() | |
if flag.NArg() != 1 { | |
usage() | |
} | |
repoRoot, err := vcs.RepoRootForImportPath(flag.Arg(0), false) | |
if err != nil { | |
log.Fatal(err) | |
} | |
fmt.Println(repoRoot.Repo) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment