From da88235bdc84db5d1ed5568cf82ac70cefe581e7 Mon Sep 17 00:00:00 2001 From: Pranav Baburaj Date: Mon, 24 May 2021 17:47:57 +0530 Subject: [PATCH] vpm: addd a show command (#10186) --- cmd/tools/vcreate.v | 5 +++++ cmd/tools/vpm.v | 45 ++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/cmd/tools/vcreate.v b/cmd/tools/vcreate.v index 6047f4d7fd..5b5b728236 100644 --- a/cmd/tools/vcreate.v +++ b/cmd/tools/vcreate.v @@ -21,6 +21,10 @@ fn cerror(e string) { } fn check_name(name string) string { + if name.trim_space().len == 0 { + cerror('project name cannot be empty') + exit(1) + } if name.is_title() { mut cname := name.to_lower() if cname.contains(' ') { @@ -157,6 +161,7 @@ fn init_project() { c.write_vmod(false) c.write_main(false) c.create_git_repo('') + println("Change your module's description in `v.mod`") } diff --git a/cmd/tools/vpm.v b/cmd/tools/vpm.v index 417dfbdf6a..72bed93d0b 100644 --- a/cmd/tools/vpm.v +++ b/cmd/tools/vpm.v @@ -13,7 +13,7 @@ import v.vmod const ( default_vpm_server_urls = ['https://vpm.vlang.io'] valid_vpm_commands = ['help', 'search', 'install', 'update', 'upgrade', 'outdated', - 'list', 'remove'] + 'list', 'remove', 'show'] excluded_dirs = ['cache', 'vlib'] supported_vcs_systems = ['git', 'hg'] supported_vcs_folders = ['.git', '.hg'] @@ -91,6 +91,9 @@ fn main() { 'remove' { vpm_remove(module_names) } + 'show' { + vpm_show(module_names) + } else { println('Error: you tried to run "v $vpm_command"') println('... but the v package management tool vpm only knows about these commands:') @@ -567,3 +570,43 @@ fn get_module_meta_info(name string) ?Mod { } return error(errors.join_lines()) } + +fn vpm_show(module_names []string) { + installed_modules := get_installed_modules() + for module_name in module_names { + if module_name !in installed_modules { + module_meta_info := get_module_meta_info(module_name) or { continue } + print(' +Name: $module_meta_info.name +Homepage: $module_meta_info.url +Downloads: $module_meta_info.nr_downloads +Installed: False +-------- + ') + continue + } + path := os.join_path(os.vmodules_dir(), module_name) + mod := vmod.from_file(os.join_path(path, 'v.mod')) or { continue } + // console_output := [ + // 'Name: $mod.name', + // 'Version: $mod.version', + // 'Description: $mod.description', + // 'Homepage: $mod.repo_url', + // 'Author: $mod.author', + // 'License: $mod.license', + // 'Location: $path', + // 'Requires: ${mod.dependencies.join(', ')}', + // ].join('\n') + // println('${console_output}\n--------\n') + print('Name: $mod.name +Version: $mod.version +Description: $mod.description +Homepage: $mod.repo_url +Author: $mod.author +License: $mod.license +Location: $path +Requires: ${mod.dependencies.join(', ')} +-------- +') + } +}