@@ -258,48 +258,45 @@ fn ensure_vcs_is_installed(vcs string) bool {
258
258
return res
259
259
}
260
260
261
- fn vpm_install_from_vcs (module_names []string , vcs_key string ) {
261
+ fn vpm_install_from_vcs (modules []string , vcs_key string ) {
262
262
mut errors := 0
263
- for n in module_names {
264
- url := n.trim_space ()
265
-
266
- first_cut_pos := url.last_index ('/' ) or {
263
+ for raw_url in modules {
264
+ url := urllib.parse (raw_url) or {
267
265
errors++
268
- eprintln ('Errors while retrieving name for module "${url} " :' )
269
- eprintln (err)
266
+ eprintln ('Errors while parsing module url "${raw_url} " : ${err} ' )
270
267
continue
271
268
}
272
269
273
- mod_name := url.substr (first_cut_pos + 1 , url.len)
274
-
275
- second_cut_pos := url.substr (0 , first_cut_pos).last_index ('/' ) or {
270
+ // Module identifier based on URL.
271
+ // E.g.: `https://github.com/owner/awesome-v-project` -> `owner/awesome_v_project`
272
+ mut ident := url.path#[1 ..].replace ('-' , '_' )
273
+ owner , repo_name := ident.split_once ('/' ) or {
276
274
errors++
277
- eprintln ('Errors while retrieving name for module "${url} " :' )
278
- eprintln (err)
275
+ eprintln ('Errors while retrieving module name for: "${url} "' )
279
276
continue
280
277
}
278
+ mut final_module_path := os.real_path (os.join_path (settings.vmodules_path, owner.to_lower (),
279
+ repo_name.to_lower ()))
281
280
282
- repo_name := url.substr (second_cut_pos + 1 , first_cut_pos)
283
- mut name := os.join_path (repo_name, mod_name)
284
- mod_name_as_path := name.replace ('-' , '_' ).to_lower ()
285
- mut final_module_path := os.real_path (os.join_path (settings.vmodules_path, mod_name_as_path))
286
281
if os.exists (final_module_path) {
287
- vpm_update ([name. replace ( '-' , '_' ) ])
282
+ vpm_update ([ident ])
288
283
continue
289
284
}
285
+
290
286
if ! ensure_vcs_is_installed (vcs_key) {
291
287
errors++
292
288
eprintln ('VPM needs `${vcs_key} ` to be installed.' )
293
289
continue
294
290
}
295
- println ('Installing module "${name} " from "${url} " to "${final_module_path} " ...' )
291
+
292
+ println ('Installing module "${repo_name} " from "${url} " to "${final_module_path} " ...' )
296
293
vcs_install_cmd := '${vcs_key} ${supported_vcs_install_cmds[vcs_key]} '
297
294
cmd := '${vcs_install_cmd} "${url} " "${final_module_path} "'
298
295
verbose_println (' command: ${cmd} ' )
299
296
cmdres := os.execute (cmd)
300
297
if cmdres.exit_code != 0 {
301
298
errors++
302
- eprintln ('Failed installing module "${name } " to "${final_module_path} " .' )
299
+ eprintln ('Failed installing module "${repo_name } " to "${final_module_path} " .' )
303
300
print_failed_cmd (cmd, cmdres)
304
301
continue
305
302
}
@@ -311,7 +308,7 @@ fn vpm_install_from_vcs(module_names []string, vcs_key string) {
311
308
}
312
309
minfo := mod_name_info (manifest.name)
313
310
if final_module_path != minfo.final_module_path {
314
- println ('Relocating module from "${name } " to "${manifest.name} " ( "${minfo.final_module_path} " ) ...' )
311
+ println ('Relocating module from "${ident } " to "${manifest.name} " ("${minfo.final_module_path} ") ...' )
315
312
if os.exists (minfo.final_module_path) {
316
313
eprintln ('Warning module "${minfo.final_module_path} " already exists!' )
317
314
eprintln ('Removing module "${minfo.final_module_path} " ...' )
@@ -324,7 +321,7 @@ fn vpm_install_from_vcs(module_names []string, vcs_key string) {
324
321
}
325
322
os.mv (final_module_path, minfo.final_module_path) or {
326
323
errors++
327
- eprintln ('Errors while relocating module "${name } " :' )
324
+ eprintln ('Errors while relocating module "${repo_name } " :' )
328
325
eprintln (err)
329
326
os.rmdir_all (final_module_path) or {
330
327
errors++
@@ -334,7 +331,7 @@ fn vpm_install_from_vcs(module_names []string, vcs_key string) {
334
331
}
335
332
continue
336
333
}
337
- println ('Module "${name } " relocated to "${manifest.name} " successfully.' )
334
+ println ('Module "${repo_name } " relocated to "${manifest.name} " successfully.' )
338
335
publisher_dir := final_module_path.all_before_last (os.path_separator)
339
336
if os.is_dir_empty (publisher_dir) {
340
337
os.rmdir (publisher_dir) or {
@@ -345,9 +342,9 @@ fn vpm_install_from_vcs(module_names []string, vcs_key string) {
345
342
}
346
343
final_module_path = minfo.final_module_path
347
344
}
348
- name = manifest.name
345
+ ident = manifest.name
349
346
}
350
- resolve_dependencies (name , final_module_path, module_names )
347
+ resolve_dependencies (ident , final_module_path, modules )
351
348
}
352
349
if errors > 0 {
353
350
exit (1 )
0 commit comments