@@ -60,6 +60,11 @@ var installCmd = &cobra.Command{
6060 },
6161}
6262
63+ func init () {
64+ jww .SetStdoutThreshold (jww .LevelInfo )
65+ rootCmd .AddCommand (installCmd )
66+ }
67+
6368func getModule (moduleName string , moduleMeta module , wg * sync.WaitGroup ) {
6469 defer wg .Done ()
6570
@@ -89,26 +94,21 @@ func getModule(moduleName string, moduleMeta module, wg *sync.WaitGroup) {
8994 pathWanted := path .Join (tmpDirectory , modulePath )
9095
9196 err := os .Rename (directory , tmpDirectory )
92- CheckIfError (err )
97+ CheckIfError (moduleName , err )
9398
9499 err = copy .Copy (pathWanted , directory )
95- CheckIfError (err )
100+ CheckIfError (moduleName , err )
96101 os .RemoveAll (tmpDirectory )
97102 }
98103 // Cleanup .git directoriy
99104 os .RemoveAll (path .Join (directory , ".git" ))
100105}
101106
102- func init () {
103- jww .SetStdoutThreshold (jww .LevelInfo )
104- rootCmd .AddCommand (installCmd )
105- }
106-
107107func getRegistrySource (name string , source string , version string ) (string , string ) {
108108 jww .INFO .Printf ("[%s] Looking up %s version %s in Terraform registry" , name , source , version )
109109 if version == "master" {
110110 err := errors .New ("Registry module version must be specified" )
111- CheckIfError (err )
111+ CheckIfError (name , err )
112112 }
113113 src := strings .Split (source , "/" )
114114 namespace , name , provider := src [0 ], src [1 ], src [2 ]
@@ -122,11 +122,11 @@ func getRegistrySource(name string, source string, version string) (string, stri
122122
123123 client := & http.Client {}
124124 req , err := http .NewRequest ("GET" , registryDownloadURL , nil )
125- CheckIfError (err )
125+ CheckIfError (name , err )
126126
127127 req .Header .Set ("User-Agent" , "XTerrafile (https://github.com/devopsmakers/xterrafile)" )
128128 resp , err := client .Do (req )
129- CheckIfError (err )
129+ CheckIfError (name , err )
130130 defer resp .Body .Close ()
131131
132132 var githubDownloadURL = ""
@@ -141,7 +141,7 @@ func getRegistrySource(name string, source string, version string) (string, stri
141141 return source , version
142142 }
143143 err = errors .New ("Unable to find module / version download url" )
144- CheckIfError (err )
144+ CheckIfError (name , err )
145145 return "" , "" // Never reacbhes here
146146}
147147
@@ -156,7 +156,7 @@ func validRegistry(source string) bool {
156156func copyFile (name string , src string , dst string ) {
157157 jww .INFO .Printf ("[%s] Copying from %s" , name , src )
158158 err := copy .Copy (src , dst )
159- CheckIfError (err )
159+ CheckIfError (name , err )
160160}
161161
162162func gitCheckout (name string , repo string , version string , directory string ) {
@@ -165,19 +165,19 @@ func gitCheckout(name string, repo string, version string, directory string) {
165165 r , err := git .PlainClone (directory , false , & git.CloneOptions {
166166 URL : repo ,
167167 })
168- CheckIfError (err )
168+ CheckIfError (name , err )
169169
170170 h , err := r .ResolveRevision (plumbing .Revision (version ))
171171 if err != nil {
172172 h , err = r .ResolveRevision (plumbing .Revision ("origin/" + version ))
173173 }
174- CheckIfError (err )
174+ CheckIfError (name , err )
175175
176176 w , err := r .Worktree ()
177- CheckIfError (err )
177+ CheckIfError (name , err )
178178
179179 err = w .Checkout (& git.CheckoutOptions {
180180 Hash : plumbing .NewHash (h .String ()),
181181 })
182- CheckIfError (err )
182+ CheckIfError (name , err )
183183}
0 commit comments