mirror of
https://github.com/vlang/v.git
synced 2025-09-13 14:32:26 +03:00
vlib,tools: add an arrays.diff
module, implement a simple platform independent tool v diff file1.txt file2.txt
using it (#24428)
This commit is contained in:
parent
1070378a46
commit
3291372c57
5 changed files with 505 additions and 0 deletions
37
cmd/tools/vdiff.v
Normal file
37
cmd/tools/vdiff.v
Normal file
|
@ -0,0 +1,37 @@
|
|||
import os
|
||||
import flag
|
||||
import term
|
||||
import arrays.diff
|
||||
|
||||
fn main() {
|
||||
mut fp := flag.new_flag_parser(os.args[1..])
|
||||
fp.application('v diff')
|
||||
fp.version('0.0.1')
|
||||
fp.description('Compare files line by line. Example: `v diff examples/hello_world.v examples/log.v`')
|
||||
fp.arguments_description('file1 file2')
|
||||
fp.skip_executable()
|
||||
fp.limit_free_args_to_at_least(2)!
|
||||
|
||||
if fp.bool('help', `h`, false, 'Show this help screen.') {
|
||||
println(fp.usage())
|
||||
exit(0)
|
||||
}
|
||||
|
||||
args := fp.finalize() or {
|
||||
eprintln('Argument error: ${err}')
|
||||
exit(1)
|
||||
}
|
||||
|
||||
src := os.read_lines(args[0])!
|
||||
dst := os.read_lines(args[1])!
|
||||
mut ctx := diff.diff(src, dst)
|
||||
patch := ctx.generate_patch(
|
||||
colorful: term.can_show_color_on_stdout()
|
||||
block_header: true
|
||||
unified: 3
|
||||
)
|
||||
if patch.len > 0 {
|
||||
print(patch)
|
||||
exit(1)
|
||||
}
|
||||
}
|
|
@ -24,6 +24,7 @@ const external_tools = [
|
|||
'complete',
|
||||
'compress',
|
||||
'cover',
|
||||
'diff',
|
||||
'doc',
|
||||
'doctor',
|
||||
'download',
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue