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

vfmt: handle file paths with spaces

This commit is contained in:
Delyan Angelov 2020-05-14 09:07:14 +03:00
parent d830620651
commit 74005b4362
2 changed files with 17 additions and 2 deletions

View File

@ -100,7 +100,7 @@ fn main() {
for file in files {
fpath := os.real_path(file)
mut worker_command_array := cli_args_no_files.clone()
worker_command_array << ['-worker', fpath]
worker_command_array << ['-worker', util.quote_path_with_spaces(fpath)]
worker_cmd := worker_command_array.join(' ')
if foptions.is_verbose {
eprintln('vfmt worker_cmd: $worker_cmd')

View File

@ -102,7 +102,7 @@ pub fn launch_tool(is_verbose bool, tool_name string) {
vexe := pref.vexe_path()
vroot := os.dir(vexe)
set_vroot_folder(vroot)
tool_args := os.args[1..].join(' ')
tool_args := args_quote_paths_with_spaces(os.args[1..])
tool_exe := path_of_executable(os.real_path('$vroot/cmd/tools/$tool_name'))
tool_source := os.real_path('$vroot/cmd/tools/${tool_name}.v')
tool_command := '"$tool_exe" $tool_args'
@ -162,6 +162,21 @@ pub fn launch_tool(is_verbose bool, tool_name string) {
exit(os.system(tool_command))
}
pub fn quote_path_with_spaces(s string) string {
if s.contains(' ') {
return '"${s}"'
}
return s
}
pub fn args_quote_paths_with_spaces(args []string) string {
mut res := []string{}
for a in args {
res << quote_path_with_spaces( a )
}
return res.join(' ')
}
pub fn path_of_executable(path string) string {
$if windows {
return path + '.exe'