mirror of
https://github.com/vlang/v.git
synced 2025-09-13 09:25:45 -04:00
v.util: improve code related to diff tool specified via environment, add check if the diff tool exists (#21240)
This commit is contained in:
parent
af4111b9de
commit
fa321ed874
@ -9,15 +9,13 @@ pub fn find_working_diff_command() !string {
|
|||||||
env_difftool := os.getenv('VDIFF_TOOL')
|
env_difftool := os.getenv('VDIFF_TOOL')
|
||||||
env_diffopts := os.getenv('VDIFF_OPTIONS')
|
env_diffopts := os.getenv('VDIFF_OPTIONS')
|
||||||
if env_difftool != '' {
|
if env_difftool != '' {
|
||||||
|
os.find_abs_path_of_executable(env_difftool) or {
|
||||||
|
return error('could not find specified VDIFF_TOOL `${env_difftool}`')
|
||||||
|
}
|
||||||
return '${env_difftool} ${env_diffopts}'
|
return '${env_difftool} ${env_diffopts}'
|
||||||
}
|
}
|
||||||
mut known_diff_tools := []string{}
|
known_diff_tools := ['colordiff', 'gdiff', 'diff', 'colordiff.exe', 'diff.exe', 'opendiff',
|
||||||
if env_difftool.len > 0 {
|
'code', 'code.cmd'] // NOTE: code.cmd is the Windows variant of the `code` cli tool
|
||||||
known_diff_tools << env_difftool
|
|
||||||
}
|
|
||||||
known_diff_tools << ['colordiff', 'gdiff', 'diff', 'colordiff.exe', 'diff.exe', 'opendiff',
|
|
||||||
'code', 'code.cmd']
|
|
||||||
// NOTE: code.cmd is the Windows variant of the `code` cli tool
|
|
||||||
for diffcmd in known_diff_tools {
|
for diffcmd in known_diff_tools {
|
||||||
if diffcmd == 'opendiff' {
|
if diffcmd == 'opendiff' {
|
||||||
os.find_abs_path_of_executable('opendiff') or { continue }
|
os.find_abs_path_of_executable('opendiff') or { continue }
|
||||||
@ -28,15 +26,10 @@ pub fn find_working_diff_command() !string {
|
|||||||
return diffcmd
|
return diffcmd
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
p := os.execute('${diffcmd} --version')
|
p := os.execute('${diffcmd} --version')
|
||||||
if p.exit_code < 0 {
|
if p.exit_code < 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if p.exit_code == 127 && diffcmd == env_difftool {
|
|
||||||
// user setup is wonky, fix it
|
|
||||||
return error('could not find specified VDIFF_TOOL ${diffcmd}')
|
|
||||||
}
|
|
||||||
if p.exit_code == 0 { // success
|
if p.exit_code == 0 { // success
|
||||||
// TODO: proper implemenation of --color flag
|
// TODO: proper implemenation of --color flag
|
||||||
$if !macos {
|
$if !macos {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user