1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

vfmt: change all '$expr' to '${expr}' (#16428)

This commit is contained in:
yuyi
2022-11-15 21:53:13 +08:00
committed by GitHub
parent 56239b4a23
commit 017ace6ea7
859 changed files with 7156 additions and 7135 deletions

View File

@@ -66,7 +66,7 @@ fn main() {
// args are: vpm [options] SUBCOMMAND module names
params := cmdline.only_non_options(os.args[1..])
options := cmdline.only_options(os.args[1..])
verbose_println('cli params: $params')
verbose_println('cli params: ${params}')
if params.len < 1 {
vpm_help()
exit(5)
@@ -126,10 +126,10 @@ fn main() {
vpm_show(module_names)
}
else {
eprintln('Error: you tried to run "v $vpm_command"')
eprintln('Error: you tried to run "v ${vpm_command}"')
eprintln('... but the v package management tool vpm only knows about these commands:')
for validcmd in valid_vpm_commands {
eprintln(' v $validcmd')
eprintln(' v ${validcmd}')
}
exit(3)
}
@@ -156,7 +156,7 @@ fn vpm_search(keywords []string) {
continue
}
if index == 0 {
println('Search results for "$joined":\n')
println('Search results for "${joined}":\n')
}
index++
mut parts := mod.split('.')
@@ -168,17 +168,17 @@ fn vpm_search(keywords []string) {
parts[0] = ' by ${parts[0]} '
}
installed := if mod in installed_modules { ' (installed)' } else { '' }
println('${index}. ${parts[1]}${parts[0]}[$mod]$installed')
println('${index}. ${parts[1]}${parts[0]}[${mod}]${installed}')
break
}
}
if index == 0 {
vexe := os.getenv('VEXE')
vroot := os.real_path(os.dir(vexe))
mut messages := ['No module(s) found for `$joined` .']
mut messages := ['No module(s) found for `${joined}` .']
for vlibmod in search_keys {
if os.is_dir(os.join_path(vroot, 'vlib', vlibmod)) {
messages << 'There is already an existing "$vlibmod" module in vlib, so you can just `import $vlibmod` .'
messages << 'There is already an existing "${vlibmod}" module in vlib, so you can just `import ${vlibmod}` .'
}
}
for m in messages {
@@ -195,7 +195,7 @@ fn vpm_install_from_vpm(module_names []string) {
name := n.trim_space().replace('_', '-')
mod := get_module_meta_info(name) or {
errors++
eprintln('Errors while retrieving meta data for module $name:')
eprintln('Errors while retrieving meta data for module ${name}:')
eprintln(err)
continue
}
@@ -205,12 +205,12 @@ fn vpm_install_from_vpm(module_names []string) {
}
if vcs !in supported_vcs_systems {
errors++
eprintln('Skipping module "$name", since it uses an unsupported VCS {$vcs} .')
eprintln('Skipping module "${name}", since it uses an unsupported VCS {${vcs}} .')
continue
}
if !ensure_vcs_is_installed(vcs) {
errors++
eprintln('VPM needs `$vcs` to be installed.')
eprintln('VPM needs `${vcs}` to be installed.')
continue
}
//
@@ -219,14 +219,14 @@ fn vpm_install_from_vpm(module_names []string) {
vpm_update([name])
continue
}
println('Installing module "$name" from "$mod.url" to "$minfo.final_module_path" ...')
println('Installing module "${name}" from "${mod.url}" to "${minfo.final_module_path}" ...')
vcs_install_cmd := supported_vcs_install_cmds[vcs]
cmd := '$vcs_install_cmd "$mod.url" "$minfo.final_module_path"'
verbose_println(' command: $cmd')
cmd := '${vcs_install_cmd} "${mod.url}" "${minfo.final_module_path}"'
verbose_println(' command: ${cmd}')
cmdres := os.execute(cmd)
if cmdres.exit_code != 0 {
errors++
eprintln('Failed installing module "$name" to "$minfo.final_module_path" .')
eprintln('Failed installing module "${name}" to "${minfo.final_module_path}" .')
print_failed_cmd(cmd, cmdres)
continue
}
@@ -238,8 +238,8 @@ fn vpm_install_from_vpm(module_names []string) {
}
fn print_failed_cmd(cmd string, cmdres os.Result) {
verbose_println('Failed command: $cmd')
verbose_println('Failed command output:\n$cmdres.output')
verbose_println('Failed command: ${cmd}')
verbose_println('Failed command output:\n${cmdres.output}')
}
fn ensure_vcs_is_installed(vcs string) bool {
@@ -260,7 +260,7 @@ fn vpm_install_from_vcs(module_names []string, vcs_key string) {
first_cut_pos := url.last_index('/') or {
errors++
eprintln('Errors while retrieving name for module "$url" :')
eprintln('Errors while retrieving name for module "${url}" :')
eprintln(err)
continue
}
@@ -269,7 +269,7 @@ fn vpm_install_from_vcs(module_names []string, vcs_key string) {
second_cut_pos := url.substr(0, first_cut_pos).last_index('/') or {
errors++
eprintln('Errors while retrieving name for module "$url" :')
eprintln('Errors while retrieving name for module "${url}" :')
eprintln(err)
continue
}
@@ -284,17 +284,17 @@ fn vpm_install_from_vcs(module_names []string, vcs_key string) {
}
if !ensure_vcs_is_installed(vcs_key) {
errors++
eprintln('VPM needs `$vcs_key` to be installed.')
eprintln('VPM needs `${vcs_key}` to be installed.')
continue
}
println('Installing module "$name" from "$url" to "$final_module_path" ...')
println('Installing module "${name}" from "${url}" to "${final_module_path}" ...')
vcs_install_cmd := supported_vcs_install_cmds[vcs_key]
cmd := '$vcs_install_cmd "$url" "$final_module_path"'
verbose_println(' command: $cmd')
cmd := '${vcs_install_cmd} "${url}" "${final_module_path}"'
verbose_println(' command: ${cmd}')
cmdres := os.execute(cmd)
if cmdres.exit_code != 0 {
errors++
eprintln('Failed installing module "$name" to "$final_module_path" .')
eprintln('Failed installing module "${name}" to "${final_module_path}" .')
print_failed_cmd(cmd, cmdres)
continue
}
@@ -306,30 +306,30 @@ fn vpm_install_from_vcs(module_names []string, vcs_key string) {
return
}
minfo := mod_name_info(vmod.name)
println('Relocating module from "$name" to "$vmod.name" ( "$minfo.final_module_path" ) ...')
println('Relocating module from "${name}" to "${vmod.name}" ( "${minfo.final_module_path}" ) ...')
if os.exists(minfo.final_module_path) {
eprintln('Warning module "$minfo.final_module_path" already exsits!')
eprintln('Removing module "$minfo.final_module_path" ...')
eprintln('Warning module "${minfo.final_module_path}" already exsits!')
eprintln('Removing module "${minfo.final_module_path}" ...')
os.rmdir_all(minfo.final_module_path) or {
errors++
println('Errors while removing "$minfo.final_module_path" :')
println('Errors while removing "${minfo.final_module_path}" :')
println(err)
continue
}
}
os.mv(final_module_path, minfo.final_module_path) or {
errors++
eprintln('Errors while relocating module "$name" :')
eprintln('Errors while relocating module "${name}" :')
eprintln(err)
os.rmdir_all(final_module_path) or {
errors++
eprintln('Errors while removing "$final_module_path" :')
eprintln('Errors while removing "${final_module_path}" :')
eprintln(err)
continue
}
continue
}
println('Module "$name" relocated to "$vmod.name" successfully.')
println('Module "${name}" relocated to "${vmod.name}" successfully.')
final_module_path = minfo.final_module_path
name = vmod.name
}
@@ -387,23 +387,23 @@ fn vpm_update(m []string) {
zname := url_to_module_name(modulename)
final_module_path := valid_final_path_of_existing_module(modulename) or { continue }
os.chdir(final_module_path) or {}
println('Updating module "$zname" in "$final_module_path" ...')
println('Updating module "${zname}" in "${final_module_path}" ...')
vcs := vcs_used_in_dir(final_module_path) or { continue }
if !ensure_vcs_is_installed(vcs[0]) {
errors++
println('VPM needs `$vcs` to be installed.')
println('VPM needs `${vcs}` to be installed.')
continue
}
vcs_cmd := supported_vcs_update_cmds[vcs[0]]
verbose_println(' command: $vcs_cmd')
vcs_res := os.execute('$vcs_cmd')
verbose_println(' command: ${vcs_cmd}')
vcs_res := os.execute('${vcs_cmd}')
if vcs_res.exit_code != 0 {
errors++
println('Failed updating module "$zname" in "$final_module_path" .')
println('Failed updating module "${zname}" in "${final_module_path}" .')
print_failed_cmd(vcs_cmd, vcs_res)
continue
} else {
verbose_println(' $vcs_res.output.trim_space()')
verbose_println(' ${vcs_res.output.trim_space()}')
}
resolve_dependencies(modulename, final_module_path, module_names)
}
@@ -424,9 +424,9 @@ fn get_outdated() ?[]string {
for step in vcs_cmd_steps {
res := os.execute(step)
if res.exit_code < 0 {
verbose_println('Error command: $step')
verbose_println('Error details:\n$res.output')
return error('Error while checking latest commits for "$name" .')
verbose_println('Error command: ${step}')
verbose_println('Error details:\n${res.output}')
return error('Error while checking latest commits for "${name}" .')
}
if vcs[0] == 'hg' {
if res.exit_code == 1 {
@@ -457,7 +457,7 @@ fn vpm_outdated() {
if outdated.len > 0 {
eprintln('Outdated modules:')
for m in outdated {
eprintln(' $m')
eprintln(' ${m}')
}
} else {
println('Modules are up to date.')
@@ -486,10 +486,10 @@ fn vpm_remove(module_names []string) {
}
for name in module_names {
final_module_path := valid_final_path_of_existing_module(name) or { continue }
eprintln('Removing module "$name" ...')
verbose_println('removing folder $final_module_path')
eprintln('Removing module "${name}" ...')
verbose_println('removing folder ${final_module_path}')
os.rmdir_all(final_module_path) or {
verbose_println('error while removing "$final_module_path": $err.msg()')
verbose_println('error while removing "${final_module_path}": ${err.msg()}')
}
// delete author directory if it is empty
author := name.split('.')[0]
@@ -498,9 +498,9 @@ fn vpm_remove(module_names []string) {
continue
}
if os.is_dir_empty(author_dir) {
verbose_println('removing author folder $author_dir')
verbose_println('removing author folder ${author_dir}')
os.rmdir(author_dir) or {
verbose_println('error while removing "$author_dir": $err.msg()')
verbose_println('error while removing "${author_dir}": ${err.msg()}')
}
}
}
@@ -510,15 +510,15 @@ fn valid_final_path_of_existing_module(modulename string) ?string {
name := if mod := get_mod_by_url(modulename) { mod.name } else { modulename }
minfo := mod_name_info(name)
if !os.exists(minfo.final_module_path) {
eprintln('No module with name "$minfo.mname_normalised" exists at $minfo.final_module_path')
eprintln('No module with name "${minfo.mname_normalised}" exists at ${minfo.final_module_path}')
return none
}
if !os.is_dir(minfo.final_module_path) {
eprintln('Skipping "$minfo.final_module_path", since it is not a folder.')
eprintln('Skipping "${minfo.final_module_path}", since it is not a folder.')
return none
}
vcs_used_in_dir(minfo.final_module_path) or {
eprintln('Skipping "$minfo.final_module_path", since it does not use a supported vcs.')
eprintln('Skipping "${minfo.final_module_path}", since it does not use a supported vcs.')
return none
}
return minfo.final_module_path
@@ -526,7 +526,7 @@ fn valid_final_path_of_existing_module(modulename string) ?string {
fn ensure_vmodules_dir_exist() {
if !os.is_dir(settings.vmodules_path) {
println('Creating "$settings.vmodules_path/" ...')
println('Creating "${settings.vmodules_path}/" ...')
os.mkdir(settings.vmodules_path) or { panic(err) }
}
}
@@ -566,7 +566,7 @@ fn get_installed_modules() []string {
mods := os.ls(adir) or { continue }
for m in mods {
vcs_used_in_dir(os.join_path(adir, m)) or { continue }
modules << '${author}.$m'
modules << '${author}.${m}'
}
}
return modules
@@ -601,7 +601,7 @@ fn get_all_modules() []string {
url := get_working_server_url()
r := http.get(url) or { panic(err) }
if r.status_code != 200 {
eprintln('Failed to search vpm.vlang.io. Status code: $r.status_code')
eprintln('Failed to search vpm.vlang.io. Status code: ${r.status_code}')
exit(1)
}
s := r.body
@@ -656,14 +656,14 @@ fn resolve_dependencies(name string, module_path string, module_names []string)
}
}
if deps.len > 0 {
println('Resolving $deps.len dependencies for module "$name" ...')
verbose_println('Found dependencies: $deps')
println('Resolving ${deps.len} dependencies for module "${name}" ...')
verbose_println('Found dependencies: ${deps}')
vpm_install(deps, Source.vpm)
}
}
fn parse_vmod(data string) !Vmod {
manifest := vmod.decode(data) or { return error('Parsing v.mod file failed, $err') }
manifest := vmod.decode(data) or { return error('Parsing v.mod file failed, ${err}') }
mut vmod := Vmod{}
vmod.name = manifest.name
vmod.version = manifest.version
@@ -678,9 +678,9 @@ fn get_working_server_url() string {
vpm_server_urls
}
for url in server_urls {
verbose_println('Trying server url: $url')
verbose_println('Trying server url: ${url}')
http.head(url) or {
verbose_println(' $url failed.')
verbose_println(' ${url} failed.')
continue
}
return url
@@ -720,7 +720,7 @@ fn verbose_println(s string) {
fn get_mod_by_url(name string) ?Mod {
if purl := urllib.parse(name) {
verbose_println('purl: $purl')
verbose_println('purl: ${purl}')
mod := Mod{
name: purl.path.trim_left('/').trim_right('/').replace('/', '.')
url: name
@@ -728,7 +728,7 @@ fn get_mod_by_url(name string) ?Mod {
verbose_println(mod.str())
return mod
}
return error('invalid url: $name')
return error('invalid url: ${name}')
}
fn get_module_meta_info(name string) ?Mod {
@@ -738,19 +738,19 @@ fn get_module_meta_info(name string) ?Mod {
mut errors := []string{}
for server_url in vpm_server_urls {
modurl := server_url + '/jsmod/$name'
verbose_println('Retrieving module metadata from: "$modurl" ...')
modurl := server_url + '/jsmod/${name}'
verbose_println('Retrieving module metadata from: "${modurl}" ...')
r := http.get(modurl) or {
errors << 'Http server did not respond to our request for "$modurl" .'
errors << 'Error details: $err'
errors << 'Http server did not respond to our request for "${modurl}" .'
errors << 'Error details: ${err}'
continue
}
if r.status_code == 404 || r.body.trim_space() == '404' {
errors << 'Skipping module "$name", since "$server_url" reported that "$name" does not exist.'
errors << 'Skipping module "${name}", since "${server_url}" reported that "${name}" does not exist.'
continue
}
if r.status_code != 200 {
errors << 'Skipping module "$name", since "$server_url" responded with $r.status_code http status code. Please try again later.'
errors << 'Skipping module "${name}", since "${server_url}" responded with ${r.status_code} http status code. Please try again later.'
continue
}
s := r.body
@@ -760,11 +760,11 @@ fn get_module_meta_info(name string) ?Mod {
continue
}
mod := json.decode(Mod, s) or {
errors << 'Skipping module "$name", since its information is not in json format.'
errors << 'Skipping module "${name}", since its information is not in json format.'
continue
}
if '' == mod.url || '' == mod.name {
errors << 'Skipping module "$name", since it is missing name or url information.'
errors << 'Skipping module "${name}", since it is missing name or url information.'
continue
}
return mod
@@ -778,9 +778,9 @@ fn vpm_show(module_names []string) {
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
Name: ${module_meta_info.name}
Homepage: ${module_meta_info.url}
Downloads: ${module_meta_info.nr_downloads}
Installed: False
--------
')
@@ -788,13 +788,13 @@ Installed: False
}
path := os.join_path(os.vmodules_dir(), module_name.replace('.', os.path_separator))
mod := vmod.from_file(os.join_path(path, 'v.mod')) or { continue }
print('Name: $mod.name
Version: $mod.version
Description: $mod.description
Homepage: $mod.repo_url
Author: $mod.author
License: $mod.license
Location: $path
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(', ')}
--------
')