...
1
15
16
17
18
19
20
21
22
23
24
25 package main
26
27 import (
28 "flag"
29 "log"
30
31 "golang.org/x/tools/go/vcs"
32 )
33
34 var (
35
36 importpath = flag.String("importpath", "", "Go importpath to the repository fetch")
37 dest = flag.String("dest", "", "destination directory")
38
39
40 remote = flag.String("remote", "", "The URI of the remote repository. Must be used with the --vcs flag.")
41 cmd = flag.String("vcs", "", "Version control system to use to fetch the repository. Should be one of: git,hg,svn,bzr. Must be used with the --remote flag.")
42 rev = flag.String("rev", "", "target revision")
43
44
45 version = flag.String("version", "", "module version. Must be semantic version or pseudo-version.")
46 sum = flag.String("sum", "", "hash of module contents")
47 )
48
49
50 var repoRootForImportPath = vcs.RepoRootForImportPath
51
52 func main() {
53 log.SetFlags(0)
54 log.SetPrefix("fetch_repo: ")
55
56 flag.Parse()
57 if *importpath == "" {
58 log.Fatal("-importpath must be set")
59 }
60 if *dest == "" {
61 log.Fatal("-dest must be set")
62 }
63 if flag.NArg() != 0 {
64 log.Fatal("fetch_repo does not accept positional arguments")
65 }
66
67 if *version != "" {
68 if *remote != "" {
69 log.Fatal("-remote must not be set in module mode")
70 }
71 if *cmd != "" {
72 log.Fatal("-vcs must not be set in module mode")
73 }
74 if *rev != "" {
75 log.Fatal("-rev must not be set in module mode")
76 }
77 if *version == "" {
78 log.Fatal("-version must be set in module mode")
79 }
80 if *sum == "" {
81 log.Fatal("-sum must be set in module mode")
82 }
83 if err := fetchModule(*dest, *importpath, *version, *sum); err != nil {
84 log.Fatal(err)
85 }
86 } else {
87 if *version != "" {
88 log.Fatal("-version must not be set in repository mode")
89 }
90 if *sum != "" {
91 log.Fatal("-sum must not be set in repository mode")
92 }
93 if *rev == "" {
94 log.Fatal("-rev must be set in repository mode")
95 }
96 if err := fetchRepo(*dest, *remote, *cmd, *importpath, *rev); err != nil {
97 log.Fatal(err)
98 }
99 }
100 }
101
View as plain text