diff --git a/cmd/tools/vpm/common.v b/cmd/tools/vpm/common.v index 1f1c9c75a6f540..4ee7fbf9966b6d 100644 --- a/cmd/tools/vpm/common.v +++ b/cmd/tools/vpm/common.v @@ -234,7 +234,7 @@ fn ensure_vcs_is_installed(vcs &VCS) ! { } fn increment_module_download_count(name string) ! { - if no_dl_count_increment { + if settings.no_dl_count_increment { println('Skipping download count increment for "${name}".') return } diff --git a/cmd/tools/vpm/install.v b/cmd/tools/vpm/install.v index bb359ea842da50..8416c3335d73ad 100644 --- a/cmd/tools/vpm/install.v +++ b/cmd/tools/vpm/install.v @@ -5,7 +5,7 @@ import v.vmod import v.help import net.urllib -fn vpm_install(requested_modules []string, opts []string) { +fn vpm_install(requested_modules []string) { if settings.is_help { help.print_and_exit('vpm') } @@ -34,7 +34,7 @@ fn vpm_install(requested_modules []string, opts []string) { mut vpm_modules := modules.filter(it !in external_modules) installed_modules := get_installed_modules() - if installed_modules.len > 0 && '--once' in opts { + if installed_modules.len > 0 && settings.is_once { mut already_installed := []string{} if external_modules.len > 0 { mut i_deleted := []int{} @@ -79,8 +79,7 @@ fn vpm_install(requested_modules []string, opts []string) { vpm_install_from_vpm(vpm_modules) } if external_modules.len > 0 { - vcs := if '--hg' in opts { supported_vcs['hg'] } else { supported_vcs['git'] } - vpm_install_from_vcs(external_modules, vcs) + vpm_install_from_vcs(external_modules, supported_vcs[settings.vcs]) } } diff --git a/cmd/tools/vpm/settings.v b/cmd/tools/vpm/settings.v new file mode 100644 index 00000000000000..c3edb7ad83bd81 --- /dev/null +++ b/cmd/tools/vpm/settings.v @@ -0,0 +1,30 @@ +module main + +import os +import os.cmdline + +struct VpmSettings { +mut: + is_help bool + is_once bool + is_verbose bool + server_urls []string + vcs string + vmodules_path string + no_dl_count_increment bool +} + +fn init_settings() VpmSettings { + args := os.args[1..] + opts := cmdline.only_options(args) + cmds := cmdline.only_non_options(args) + return VpmSettings{ + is_help: '-h' in opts || '--help' in opts || 'help' in cmds + is_once: '--once' in opts + is_verbose: '-v' in opts + vcs: if '--hg' in opts { 'hg' } else { 'git' } + server_urls: cmdline.options(args, '--server-urls') + vmodules_path: os.vmodules_dir() + no_dl_count_increment: os.getenv('VPM_NO_INCREMENT') == '1' + } +} diff --git a/cmd/tools/vpm/vpm.v b/cmd/tools/vpm/vpm.v index 4afed47036b1ef..587c71856f83a9 100644 --- a/cmd/tools/vpm/vpm.v +++ b/cmd/tools/vpm/vpm.v @@ -9,14 +9,6 @@ import rand import v.help import v.vmod -struct VpmSettings { -mut: - is_help bool - is_verbose bool - server_urls []string - vmodules_path string -} - struct VCS { dir string cmd string @@ -29,8 +21,7 @@ struct VCS { } const ( - settings = &VpmSettings{} - no_dl_count_increment = os.getenv('VPM_NO_INCREMENT') == '1' + settings = init_settings() default_vpm_server_urls = ['https://vpm.vlang.io', 'https://vpm.url4e.com'] vpm_server_urls = rand.shuffle_clone(default_vpm_server_urls) or { [] } // ensure that all queries are distributed fairly valid_vpm_commands = ['help', 'search', 'install', 'update', 'upgrade', 'outdated', 'list', @@ -61,12 +52,10 @@ const ( ) fn main() { - init_settings() // This tool is intended to be launched by the v frontend, // which provides the path to V inside os.getenv('VEXE') // args are: vpm [options] SUBCOMMAND module names params := cmdline.only_non_options(os.args[1..]) - options := cmdline.only_options(os.args[1..]) // dump(params) if params.len < 1 { help.print_and_exit('vpm', exit_code: 5) @@ -82,7 +71,7 @@ fn main() { vpm_search(requested_modules) } 'install' { - vpm_install(requested_modules, options) + vpm_install(requested_modules) } 'update' { vpm_update(requested_modules) @@ -113,17 +102,6 @@ fn main() { } } -fn init_settings() { - mut s := &VpmSettings(unsafe { nil }) - unsafe { - s = settings - } - s.is_help = '-h' in os.args || '--help' in os.args || 'help' in os.args - s.is_verbose = '-v' in os.args - s.server_urls = cmdline.options(os.args, '-server-url') - s.vmodules_path = os.vmodules_dir() -} - fn vpm_upgrade() { outdated := get_outdated() or { exit(1) } if outdated.len > 0 {