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

vfmt: extract v.util.find_working_diff_command, color_compare_files

This commit is contained in:
Delyan Angelov
2020-04-29 11:50:33 +03:00
parent dd3434598c
commit 0e765e34be
6 changed files with 36 additions and 57 deletions

View File

@ -181,11 +181,11 @@ fn (foptions &FormatOptions) post_process_file(file, formatted_file_path string)
return
}
if foptions.is_diff {
diff_cmd := find_working_diff_command() or {
diff_cmd := util.find_working_diff_command() or {
eprintln('No working "diff" CLI command found.')
return
}
os.system('$diff_cmd --minimal --text --unified=2 --show-function-line="fn " "$file" "$formatted_file_path" ')
println(util.color_compare_files(diff_cmd, file, formatted_file_path))
return
}
fc := os.read_file(file) or {
@ -224,17 +224,6 @@ fn (foptions &FormatOptions) post_process_file(file, formatted_file_path string)
print(formatted_fc)
}
fn find_working_diff_command() ?string {
for diffcmd in ['colordiff', 'diff', 'colordiff.exe', 'diff.exe'] {
p := os.exec('$diffcmd --version') or {
continue
}
if p.exit_code == 0 {
return diffcmd
}
}
return error('no working diff command found')
}
fn (f FormatOptions) str() string {
return 'FormatOptions{ is_l: $f.is_l' + ' is_w: $f.is_w' + ' is_diff: $f.is_diff' + ' is_verbose: $f.is_verbose' +