vfmt: handle file paths with spaces

pull/4893/head
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 { for file in files {
fpath := os.real_path(file) fpath := os.real_path(file)
mut worker_command_array := cli_args_no_files.clone() 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(' ') worker_cmd := worker_command_array.join(' ')
if foptions.is_verbose { if foptions.is_verbose {
eprintln('vfmt worker_cmd: $worker_cmd') 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() vexe := pref.vexe_path()
vroot := os.dir(vexe) vroot := os.dir(vexe)
set_vroot_folder(vroot) 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_exe := path_of_executable(os.real_path('$vroot/cmd/tools/$tool_name'))
tool_source := os.real_path('$vroot/cmd/tools/${tool_name}.v') tool_source := os.real_path('$vroot/cmd/tools/${tool_name}.v')
tool_command := '"$tool_exe" $tool_args' 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)) 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 { pub fn path_of_executable(path string) string {
$if windows { $if windows {
return path + '.exe' return path + '.exe'