daff 1.2.6 → 1.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -6
- data/bin/daff.rb +0 -0
- data/lib/daff.rb +6 -0
- data/lib/lib/coopy/alignment.rb +146 -169
- data/lib/lib/coopy/cell_builder.rb +1 -1
- data/lib/lib/coopy/cell_info.rb +2 -1
- data/lib/lib/coopy/column_change.rb +16 -0
- data/lib/lib/coopy/compare_flags.rb +33 -5
- data/lib/lib/coopy/compare_table.rb +219 -99
- data/lib/lib/coopy/coopy.rb +205 -99
- data/lib/lib/coopy/csv.rb +17 -22
- data/lib/lib/coopy/diff_render.rb +16 -8
- data/lib/lib/coopy/flat_cell_builder.rb +11 -8
- data/lib/lib/coopy/highlight_patch.rb +363 -63
- data/lib/lib/coopy/highlight_patch_unit.rb +1 -1
- data/lib/lib/coopy/index.rb +21 -8
- data/lib/lib/coopy/index_item.rb +7 -3
- data/lib/lib/coopy/index_pair.rb +13 -10
- data/lib/lib/coopy/merger.rb +3 -3
- data/lib/lib/coopy/meta.rb +17 -0
- data/lib/lib/coopy/mover.rb +7 -5
- data/lib/lib/coopy/ndjson.rb +2 -2
- data/lib/lib/coopy/nested_cell_builder.rb +7 -7
- data/lib/lib/coopy/ordering.rb +6 -2
- data/lib/lib/coopy/property_change.rb +16 -0
- data/lib/lib/coopy/row.rb +1 -0
- data/lib/lib/coopy/row_change.rb +42 -0
- data/lib/lib/coopy/row_stream.rb +11 -0
- data/lib/lib/coopy/simple_table.rb +84 -30
- data/lib/lib/coopy/simple_view.rb +8 -8
- data/lib/lib/coopy/sparse_sheet.rb +1 -1
- data/lib/lib/coopy/sql_column.rb +22 -10
- data/lib/lib/coopy/sql_compare.rb +397 -85
- data/lib/lib/coopy/sql_database.rb +2 -0
- data/lib/lib/coopy/sql_helper.rb +5 -0
- data/lib/lib/coopy/sql_table.rb +122 -19
- data/lib/lib/coopy/sql_table_name.rb +1 -1
- data/lib/lib/coopy/sqlite_helper.rb +250 -3
- data/lib/lib/coopy/table.rb +1 -0
- data/lib/lib/coopy/table_diff.rb +643 -464
- data/lib/lib/coopy/table_io.rb +19 -6
- data/lib/lib/coopy/table_modifier.rb +1 -1
- data/lib/lib/coopy/table_stream.rb +102 -0
- data/lib/lib/coopy/terminal_diff_render.rb +4 -3
- data/lib/lib/coopy/unit.rb +22 -2
- data/lib/lib/coopy/viterbi.rb +4 -4
- data/lib/lib/haxe/ds/int_map.rb +1 -1
- data/lib/lib/haxe/ds/string_map.rb +1 -1
- data/lib/lib/haxe/format/json_parser.rb +1 -1
- data/lib/lib/haxe/format/json_printer.rb +1 -1
- data/lib/lib/haxe/io/bytes.rb +2 -2
- data/lib/lib/haxe/io/eof.rb +1 -1
- data/lib/lib/haxe/io/output.rb +1 -1
- data/lib/lib/hx_overrides.rb +1 -1
- data/lib/lib/hx_sys.rb +9 -5
- data/lib/lib/lambda.rb +3 -3
- data/lib/lib/list.rb +1 -1
- data/lib/lib/rb/ruby_iterator.rb +2 -2
- data/lib/lib/reflect.rb +1 -1
- data/lib/lib/sys/io/file_output.rb +1 -1
- data/lib/lib/sys/io/hx_file.rb +1 -1
- data/lib/lib/x_list/list_iterator.rb +2 -2
- metadata +29 -25
- data/lib/lib/coopy/table_text.rb +0 -26
- data/lib/lib/haxe/io/bytes_buffer.rb +0 -19
- data/lib/lib/haxe/io/bytes_input.rb +0 -13
- data/lib/lib/haxe/io/bytes_output.rb +0 -33
- data/lib/lib/haxe/io/input.rb +0 -11
data/lib/lib/coopy/coopy.rb
CHANGED
@@ -5,13 +5,7 @@ module Coopy
|
|
5
5
|
class Coopy
|
6
6
|
|
7
7
|
def initialize
|
8
|
-
|
9
|
-
@format_preference = nil
|
10
|
-
@delim_preference = nil
|
11
|
-
@output_format = "copy"
|
12
|
-
@nested_output = false
|
13
|
-
@order_set = false
|
14
|
-
@order_preference = false
|
8
|
+
self.init
|
15
9
|
end
|
16
10
|
|
17
11
|
# protected - in ruby this doesn't play well with static/inline methods
|
@@ -20,18 +14,42 @@ module Coopy
|
|
20
14
|
attr_accessor :delim_preference
|
21
15
|
attr_accessor :extern_preference
|
22
16
|
attr_accessor :output_format
|
17
|
+
attr_accessor :output_format_set
|
23
18
|
attr_accessor :nested_output
|
24
19
|
attr_accessor :order_set
|
25
20
|
attr_accessor :order_preference
|
26
21
|
attr_accessor :io
|
22
|
+
attr_accessor :pretty
|
23
|
+
attr_accessor :strategy
|
24
|
+
attr_accessor :css_output
|
25
|
+
attr_accessor :fragment
|
26
|
+
attr_accessor :flags
|
27
27
|
attr_accessor :mv
|
28
28
|
|
29
|
+
def init
|
30
|
+
@extern_preference = false
|
31
|
+
@format_preference = nil
|
32
|
+
@delim_preference = nil
|
33
|
+
@output_format = "copy"
|
34
|
+
@output_format_set = false
|
35
|
+
@nested_output = false
|
36
|
+
@order_set = false
|
37
|
+
@order_preference = false
|
38
|
+
@pretty = true
|
39
|
+
@css_output = nil
|
40
|
+
@fragment = false
|
41
|
+
@flags = nil
|
42
|
+
end
|
43
|
+
|
29
44
|
def check_format(name)
|
30
45
|
return @format_preference if @extern_preference
|
31
46
|
ext = ""
|
32
47
|
pt = name.rindex(".",nil || 0) || -1
|
33
48
|
if pt >= 0
|
34
|
-
|
49
|
+
begin
|
50
|
+
_this = name[pt + 1..-1]
|
51
|
+
ext = _this.downcase
|
52
|
+
end
|
35
53
|
case(ext)
|
36
54
|
when "json"
|
37
55
|
@format_preference = "json"
|
@@ -50,13 +68,17 @@ module Coopy
|
|
50
68
|
@format_preference = "sqlite"
|
51
69
|
when "sqlite"
|
52
70
|
@format_preference = "sqlite"
|
71
|
+
when "html","htm"
|
72
|
+
@format_preference = "html"
|
73
|
+
when "www"
|
74
|
+
@format_preference = "www"
|
53
75
|
else
|
54
76
|
ext = ""
|
55
77
|
end
|
56
78
|
end
|
57
79
|
@nested_output = @format_preference == "json" || @format_preference == "ndjson"
|
58
80
|
@order_preference = !@nested_output
|
59
|
-
|
81
|
+
ext
|
60
82
|
end
|
61
83
|
|
62
84
|
def set_format(name)
|
@@ -65,15 +87,32 @@ module Coopy
|
|
65
87
|
@extern_preference = true
|
66
88
|
end
|
67
89
|
|
90
|
+
def render_table(name,t)
|
91
|
+
renderer = ::Coopy::DiffRender.new
|
92
|
+
renderer.use_pretty_arrows(@pretty)
|
93
|
+
renderer.render(t)
|
94
|
+
renderer.complete_html if !@fragment
|
95
|
+
if @format_preference == "www"
|
96
|
+
@io.send_to_browser(renderer.html)
|
97
|
+
else
|
98
|
+
self.save_text(name,renderer.html)
|
99
|
+
end
|
100
|
+
self.save_text(@css_output,renderer.sample_css) if @css_output != nil
|
101
|
+
true
|
102
|
+
end
|
103
|
+
|
68
104
|
def save_table(name,t)
|
69
105
|
self.set_format(@output_format) if @output_format != "copy"
|
70
106
|
txt = ""
|
71
107
|
self.check_format(name)
|
108
|
+
@format_preference = "csv" if @format_preference == "sqlite" && !@extern_preference
|
72
109
|
if @format_preference == "csv"
|
73
110
|
csv = ::Coopy::Csv.new(@delim_preference)
|
74
111
|
txt = csv.render_table(t)
|
75
112
|
elsif @format_preference == "ndjson"
|
76
113
|
txt = ::Coopy::Ndjson.new(t).render
|
114
|
+
elsif @format_preference == "html" || @format_preference == "www"
|
115
|
+
return self.render_table(name,t)
|
77
116
|
elsif @format_preference == "sqlite"
|
78
117
|
@io.write_stderr("! Cannot yet output to sqlite, aborting\n")
|
79
118
|
return false
|
@@ -81,7 +120,7 @@ module Coopy
|
|
81
120
|
value = ::Coopy::Coopy.jsonify(t)
|
82
121
|
txt = ::Haxe::Format::JsonPrinter._print(value,nil," ")
|
83
122
|
end
|
84
|
-
|
123
|
+
self.save_text(name,txt)
|
85
124
|
end
|
86
125
|
|
87
126
|
def save_text(name,txt)
|
@@ -90,11 +129,10 @@ module Coopy
|
|
90
129
|
else
|
91
130
|
@io.write_stdout(txt)
|
92
131
|
end
|
93
|
-
|
132
|
+
true
|
94
133
|
end
|
95
134
|
|
96
135
|
def load_table(name)
|
97
|
-
txt = @io.get_content(name)
|
98
136
|
ext = self.check_format(name)
|
99
137
|
if ext == "sqlite"
|
100
138
|
sql = @io.open_sqlite_database(name)
|
@@ -103,18 +141,27 @@ module Coopy
|
|
103
141
|
return nil
|
104
142
|
end
|
105
143
|
helper = ::Coopy::SqliteHelper.new
|
106
|
-
|
107
|
-
if
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
144
|
+
name1 = ""
|
145
|
+
if @flags == nil || @flags.tables == nil || @flags.tables.length == 0
|
146
|
+
names = helper.get_table_names(sql)
|
147
|
+
if names == nil
|
148
|
+
@io.write_stderr("! Cannot find database tables, aborting\n")
|
149
|
+
return nil
|
150
|
+
end
|
151
|
+
if names.length == 0
|
152
|
+
@io.write_stderr("! No tables in database, aborting\n")
|
153
|
+
return nil
|
154
|
+
end
|
155
|
+
name1 = names[0]
|
156
|
+
else
|
157
|
+
name1 = @flags.tables[0]
|
158
|
+
@io.write_stderr("! Cannot compare more than one table yet\n") if @flags.tables.length > 1
|
114
159
|
end
|
115
|
-
tab = ::Coopy::SqlTable.new(sql,::Coopy::SqlTableName.new(
|
160
|
+
tab = ::Coopy::SqlTable.new(sql,::Coopy::SqlTableName.new(name1),helper)
|
161
|
+
@strategy = "sql"
|
116
162
|
return tab
|
117
163
|
end
|
164
|
+
txt = @io.get_content(name)
|
118
165
|
if ext == "ndjson"
|
119
166
|
t = ::Coopy::SimpleTable.new(0,0)
|
120
167
|
ndjson = ::Coopy::Ndjson.new(t)
|
@@ -136,7 +183,7 @@ module Coopy
|
|
136
183
|
output = ::Coopy::SimpleTable.new(0,0)
|
137
184
|
csv.parse_table(txt,output)
|
138
185
|
output.trim_blank if output != nil
|
139
|
-
|
186
|
+
output
|
140
187
|
end
|
141
188
|
|
142
189
|
attr_accessor :status
|
@@ -162,7 +209,7 @@ module Coopy
|
|
162
209
|
io.write_stdout("\n")
|
163
210
|
end
|
164
211
|
r = io.command(cmd,args) if !io.async
|
165
|
-
|
212
|
+
r
|
166
213
|
end
|
167
214
|
|
168
215
|
def install_git_driver(io,formats)
|
@@ -235,14 +282,10 @@ module Coopy
|
|
235
282
|
have_diff_driver = @status[key] == 0
|
236
283
|
key = "add_diff_driver_" + _hx_str(format1)
|
237
284
|
if !@status.include?(key)
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
else
|
243
|
-
r = 0
|
244
|
-
io.write_stdout("- Already have diff driver for " + _hx_str(format1) + ", not touching it\n")
|
245
|
-
end
|
285
|
+
r = self.command(io,"git",["config","--global","diff.daff-" + _hx_str(format1) + ".command",_hx_str(@daff_cmd) + " diff --git"])
|
286
|
+
return r if r == 999
|
287
|
+
io.write_stdout("- Cleared existing daff diff driver for " + _hx_str(format1) + "\n") if have_diff_driver
|
288
|
+
io.write_stdout("- Added diff driver for " + _hx_str(format1) + "\n")
|
246
289
|
@status[key] = r
|
247
290
|
end
|
248
291
|
key = "have_merge_driver_" + _hx_str(format1)
|
@@ -264,14 +307,10 @@ module Coopy
|
|
264
307
|
end
|
265
308
|
key = "add_merge_driver_" + _hx_str(format1)
|
266
309
|
if !@status.include?(key)
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
else
|
272
|
-
r = 0
|
273
|
-
io.write_stdout("- Already have merge driver for " + _hx_str(format1) + ", not touching it\n")
|
274
|
-
end
|
310
|
+
r = self.command(io,"git",["config","--global","merge.daff-" + _hx_str(format1) + ".driver",_hx_str(@daff_cmd) + " merge --output %A %O %A %B"])
|
311
|
+
return r if r == 999
|
312
|
+
io.write_stdout("- Cleared existing daff merge driver for " + _hx_str(format1) + "\n") if have_merge_driver
|
313
|
+
io.write_stdout("- Added merge driver for " + _hx_str(format1) + "\n")
|
275
314
|
@status[key] = r
|
276
315
|
end
|
277
316
|
end
|
@@ -311,24 +350,23 @@ module Coopy
|
|
311
350
|
end
|
312
351
|
io.save_content(attr,txt) if need_update
|
313
352
|
io.write_stdout("- Done!\n")
|
314
|
-
|
353
|
+
0
|
315
354
|
end
|
316
355
|
|
317
356
|
public
|
318
357
|
|
319
358
|
def coopyhx(io)
|
359
|
+
self.init
|
320
360
|
args = io.args
|
321
361
|
return ::Coopy::Coopy.keep_around if args[0] == "--keep"
|
322
362
|
more = true
|
323
363
|
output = nil
|
324
|
-
css_output = nil
|
325
|
-
fragment = false
|
326
|
-
pretty = true
|
327
364
|
inplace = false
|
328
365
|
git = false
|
329
366
|
color = false
|
330
|
-
|
331
|
-
flags
|
367
|
+
no_color = false
|
368
|
+
@flags = ::Coopy::CompareFlags.new
|
369
|
+
@flags.always_show_header = true
|
332
370
|
while(more)
|
333
371
|
more = false
|
334
372
|
begin
|
@@ -345,30 +383,41 @@ module Coopy
|
|
345
383
|
break
|
346
384
|
elsif tag == "--css"
|
347
385
|
more = true
|
348
|
-
fragment = true
|
349
|
-
css_output = args[i + 1]
|
386
|
+
@fragment = true
|
387
|
+
@css_output = args[i + 1]
|
350
388
|
args.slice!(i,2)
|
351
389
|
break
|
352
390
|
elsif tag == "--fragment"
|
353
391
|
more = true
|
354
|
-
fragment = true
|
392
|
+
@fragment = true
|
355
393
|
args.slice!(i,1)
|
356
394
|
break
|
357
395
|
elsif tag == "--plain"
|
358
396
|
more = true
|
359
|
-
pretty = false
|
397
|
+
@pretty = false
|
360
398
|
args.slice!(i,1)
|
361
399
|
break
|
362
400
|
elsif tag == "--all"
|
363
401
|
more = true
|
364
|
-
flags.show_unchanged = true
|
402
|
+
@flags.show_unchanged = true
|
403
|
+
@flags.show_unchanged_columns = true
|
404
|
+
args.slice!(i,1)
|
405
|
+
break
|
406
|
+
elsif tag == "--all-rows"
|
407
|
+
more = true
|
408
|
+
@flags.show_unchanged = true
|
409
|
+
args.slice!(i,1)
|
410
|
+
break
|
411
|
+
elsif tag == "--all-columns"
|
412
|
+
more = true
|
413
|
+
@flags.show_unchanged_columns = true
|
365
414
|
args.slice!(i,1)
|
366
415
|
break
|
367
416
|
elsif tag == "--act"
|
368
417
|
more = true
|
369
|
-
flags.acts = {} if flags.acts == nil
|
418
|
+
@flags.acts = {} if @flags.acts == nil
|
370
419
|
begin
|
371
|
-
flags.acts[args[i + 1]] = true
|
420
|
+
@flags.acts[args[i + 1]] = true
|
372
421
|
true
|
373
422
|
end
|
374
423
|
args.slice!(i,2)
|
@@ -376,7 +425,7 @@ module Coopy
|
|
376
425
|
elsif tag == "--context"
|
377
426
|
more = true
|
378
427
|
context = args[i + 1].to_i
|
379
|
-
flags.unchanged_context = context if context >= 0
|
428
|
+
@flags.unchanged_context = context if context >= 0
|
380
429
|
args.slice!(i,2)
|
381
430
|
break
|
382
431
|
elsif tag == "--inplace"
|
@@ -391,14 +440,14 @@ module Coopy
|
|
391
440
|
break
|
392
441
|
elsif tag == "--unordered"
|
393
442
|
more = true
|
394
|
-
flags.ordered = false
|
395
|
-
flags.unchanged_context = 0
|
443
|
+
@flags.ordered = false
|
444
|
+
@flags.unchanged_context = 0
|
396
445
|
@order_set = true
|
397
446
|
args.slice!(i,1)
|
398
447
|
break
|
399
448
|
elsif tag == "--ordered"
|
400
449
|
more = true
|
401
|
-
flags.ordered = true
|
450
|
+
@flags.ordered = true
|
402
451
|
@order_set = true
|
403
452
|
args.slice!(i,1)
|
404
453
|
break
|
@@ -407,6 +456,11 @@ module Coopy
|
|
407
456
|
color = true
|
408
457
|
args.slice!(i,1)
|
409
458
|
break
|
459
|
+
elsif tag == "--no-color"
|
460
|
+
more = true
|
461
|
+
no_color = true
|
462
|
+
args.slice!(i,1)
|
463
|
+
break
|
410
464
|
elsif tag == "--input-format"
|
411
465
|
more = true
|
412
466
|
self.set_format(args[i + 1])
|
@@ -415,26 +469,36 @@ module Coopy
|
|
415
469
|
elsif tag == "--output-format"
|
416
470
|
more = true
|
417
471
|
@output_format = args[i + 1]
|
472
|
+
@output_format_set = true
|
418
473
|
args.slice!(i,2)
|
419
474
|
break
|
420
475
|
elsif tag == "--id"
|
421
476
|
more = true
|
422
|
-
flags.ids = Array.new if flags.ids == nil
|
423
|
-
flags.ids.push(args[i + 1])
|
477
|
+
@flags.ids = Array.new if @flags.ids == nil
|
478
|
+
@flags.ids.push(args[i + 1])
|
424
479
|
args.slice!(i,2)
|
425
480
|
break
|
426
481
|
elsif tag == "--ignore"
|
427
482
|
more = true
|
428
|
-
flags.
|
429
|
-
flags.columns_to_ignore.push(args[i + 1])
|
483
|
+
@flags.ignore_column(args[i + 1])
|
430
484
|
args.slice!(i,2)
|
431
485
|
break
|
432
486
|
elsif tag == "--index"
|
433
487
|
more = true
|
434
|
-
flags.always_show_order = true
|
435
|
-
flags.never_show_order = false
|
488
|
+
@flags.always_show_order = true
|
489
|
+
@flags.never_show_order = false
|
436
490
|
args.slice!(i,1)
|
437
491
|
break
|
492
|
+
elsif tag == "--www"
|
493
|
+
more = true
|
494
|
+
@output_format = "www"
|
495
|
+
@output_format_set = true
|
496
|
+
args.slice!(i,1)
|
497
|
+
elsif tag == "--table"
|
498
|
+
more = true
|
499
|
+
@flags.add_table(args[i + 1])
|
500
|
+
args.slice!(i,2)
|
501
|
+
break
|
438
502
|
end
|
439
503
|
end
|
440
504
|
end
|
@@ -460,20 +524,22 @@ module Coopy
|
|
460
524
|
io.write_stdout(" *.csv merge=daff-csv\n")
|
461
525
|
io.write_stdout("\nCreate a file called .gitconfig in your home directory (or alternatively\nopen .git/config for a particular repository) and add:\n\n")
|
462
526
|
io.write_stdout(" [diff \"daff-csv\"]\n")
|
463
|
-
io.write_stdout(" command = daff diff --
|
527
|
+
io.write_stdout(" command = daff diff --git\n")
|
464
528
|
io.write_stderr("\n")
|
465
529
|
io.write_stdout(" [merge \"daff-csv\"]\n")
|
466
530
|
io.write_stdout(" name = daff tabular merge\n")
|
467
531
|
io.write_stdout(" driver = daff merge --output %A %O %A %B\n\n")
|
468
|
-
io.write_stderr("Make sure you can run daff from the command-line as just \"daff\" - if not,\nreplace \"daff\" in the driver and command lines above with the correct way\nto call it.
|
532
|
+
io.write_stderr("Make sure you can run daff from the command-line as just \"daff\" - if not,\nreplace \"daff\" in the driver and command lines above with the correct way\nto call it. Add --no-color if your terminal does not support ANSI colors.")
|
469
533
|
io.write_stderr("\n")
|
470
534
|
return 0
|
471
535
|
end
|
472
536
|
io.write_stderr("daff can produce and apply tabular diffs.\n")
|
473
537
|
io.write_stderr("Call as:\n")
|
474
|
-
io.write_stderr(" daff [--color] [--output OUTPUT.csv] a.csv b.csv\n")
|
538
|
+
io.write_stderr(" daff [--color] [--no-color] [--output OUTPUT.csv] a.csv b.csv\n")
|
539
|
+
io.write_stderr(" daff [--output OUTPUT.html] a.csv b.csv\n")
|
475
540
|
io.write_stderr(" daff [--output OUTPUT.csv] parent.csv a.csv b.csv\n")
|
476
541
|
io.write_stderr(" daff [--output OUTPUT.ndjson] a.ndjson b.ndjson\n")
|
542
|
+
io.write_stderr(" daff [--www] a.csv b.csv\n")
|
477
543
|
io.write_stderr(" daff patch [--inplace] [--output OUTPUT.csv] a.csv patch.csv\n")
|
478
544
|
io.write_stderr(" daff merge [--inplace] [--output OUTPUT.csv] parent.csv a.csv b.csv\n")
|
479
545
|
io.write_stderr(" daff trim [--output OUTPUT.csv] source.csv\n")
|
@@ -487,24 +553,26 @@ module Coopy
|
|
487
553
|
io.write_stderr("If you need more control, here is the full list of flags:\n")
|
488
554
|
io.write_stderr(" daff diff [--output OUTPUT.csv] [--context NUM] [--all] [--act ACT] a.csv b.csv\n")
|
489
555
|
io.write_stderr(" --act ACT: show only a certain kind of change (update, insert, delete)\n")
|
490
|
-
io.write_stderr(" --all: do not prune unchanged rows\n")
|
491
|
-
io.write_stderr(" --
|
556
|
+
io.write_stderr(" --all: do not prune unchanged rows or columns\n")
|
557
|
+
io.write_stderr(" --all-rows: do not prune unchanged rows\n")
|
558
|
+
io.write_stderr(" --all-columns: do not prune unchanged columns\n")
|
559
|
+
io.write_stderr(" --color: highlight changes with terminal colors (default in terminals)\n")
|
492
560
|
io.write_stderr(" --context NUM: show NUM rows of context\n")
|
493
561
|
io.write_stderr(" --id: specify column to use as primary key (repeat for multi-column key)\n")
|
494
562
|
io.write_stderr(" --ignore: specify column to ignore completely (can repeat)\n")
|
563
|
+
io.write_stderr(" --index: include row/columns numbers from original tables\n")
|
495
564
|
io.write_stderr(" --input-format [csv|tsv|ssv|json]: set format to expect for input\n")
|
565
|
+
io.write_stderr(" --no-color: make sure terminal colors are not used\n")
|
496
566
|
io.write_stderr(" --ordered: assume row order is meaningful (default for CSV)\n")
|
497
|
-
io.write_stderr(" --output-format [csv|tsv|ssv|json|copy]: set format for output\n")
|
567
|
+
io.write_stderr(" --output-format [csv|tsv|ssv|json|copy|html]: set format for output\n")
|
568
|
+
io.write_stderr(" --table NAME: compare the named table, used with SQL sources\n")
|
498
569
|
io.write_stderr(" --unordered: assume row order is meaningless (default for json formats)\n")
|
499
570
|
io.write_stderr("\n")
|
500
|
-
io.write_stderr(" daff diff --git path old-file old-hex old-mode new-file new-hex new-mode\n")
|
501
|
-
io.write_stderr(" --git: process arguments provided by git to diff drivers\n")
|
502
|
-
io.write_stderr(" --index: include row/columns numbers from orginal tables\n")
|
503
|
-
io.write_stderr("\n")
|
504
571
|
io.write_stderr(" daff render [--output OUTPUT.html] [--css CSS.css] [--fragment] [--plain] diff.csv\n")
|
505
572
|
io.write_stderr(" --css CSS.css: generate a suitable css file to go with the html\n")
|
506
573
|
io.write_stderr(" --fragment: generate just a html fragment rather than a page\n")
|
507
574
|
io.write_stderr(" --plain: do not use fancy utf8 characters to make arrows prettier\n")
|
575
|
+
io.write_stderr(" --www: send output to a browser\n")
|
508
576
|
return 1
|
509
577
|
end
|
510
578
|
cmd1 = args[0]
|
@@ -521,18 +589,23 @@ module Coopy
|
|
521
589
|
end
|
522
590
|
if git
|
523
591
|
ct = args.length - offset
|
524
|
-
if ct != 7
|
525
|
-
io.write_stderr("Expected 7 parameters from git, but got " + _hx_str(ct) + "\n")
|
592
|
+
if ct != 7 && ct != 9
|
593
|
+
io.write_stderr("Expected 7 or 9 parameters from git, but got " + _hx_str(ct) + "\n")
|
526
594
|
return 1
|
527
595
|
end
|
528
596
|
git_args = args.slice!(offset,ct)
|
529
597
|
args.slice!(0,args.length)
|
530
598
|
offset = 0
|
531
|
-
|
599
|
+
old_display_path = git_args[0]
|
600
|
+
new_display_path = git_args[0]
|
532
601
|
old_file = git_args[1]
|
533
602
|
new_file = git_args[4]
|
534
|
-
|
535
|
-
|
603
|
+
if ct == 9
|
604
|
+
io.write_stdout(git_args[8])
|
605
|
+
new_display_path = git_args[7]
|
606
|
+
end
|
607
|
+
io.write_stdout("--- a/" + _hx_str(old_display_path) + "\n")
|
608
|
+
io.write_stdout("+++ b/" + _hx_str(new_display_path) + "\n")
|
536
609
|
args.push(old_file)
|
537
610
|
args.push(new_file)
|
538
611
|
end
|
@@ -553,6 +626,7 @@ module Coopy
|
|
553
626
|
output = args[1 + offset]
|
554
627
|
end
|
555
628
|
end
|
629
|
+
@flags.diff_strategy = @strategy
|
556
630
|
if inplace
|
557
631
|
io.write_stderr("Please do not use --inplace when specifying an output.\n") if output != nil
|
558
632
|
output = aname
|
@@ -562,16 +636,22 @@ module Coopy
|
|
562
636
|
ok = true
|
563
637
|
if cmd1 == "diff"
|
564
638
|
if !@order_set
|
565
|
-
flags.ordered = @order_preference
|
566
|
-
flags.unchanged_context = 0 if
|
639
|
+
@flags.ordered = @order_preference
|
640
|
+
@flags.unchanged_context = 0 if !@flags.ordered
|
567
641
|
end
|
568
|
-
flags.allow_nested_cells = @nested_output
|
569
|
-
ct1 = ::Coopy::Coopy.compare_tables3(parent,a,b
|
642
|
+
@flags.allow_nested_cells = @nested_output
|
643
|
+
ct1 = ::Coopy::Coopy.compare_tables3(parent,a,b,@flags)
|
570
644
|
align = ct1.align
|
571
|
-
td = ::Coopy::TableDiff.new(align
|
645
|
+
td = ::Coopy::TableDiff.new(align,@flags)
|
572
646
|
o = ::Coopy::SimpleTable.new(0,0)
|
573
647
|
td.hilite(o)
|
574
|
-
|
648
|
+
use_color = color
|
649
|
+
if !(color || no_color)
|
650
|
+
if output == "-" && @output_format == "copy"
|
651
|
+
use_color = io.is_tty if io.is_tty_known
|
652
|
+
end
|
653
|
+
end
|
654
|
+
if use_color
|
575
655
|
render = ::Coopy::TerminalDiffRender.new
|
576
656
|
tool.save_text(output,render.render(o))
|
577
657
|
else
|
@@ -582,7 +662,7 @@ module Coopy
|
|
582
662
|
patcher.apply
|
583
663
|
tool.save_table(output,a)
|
584
664
|
elsif cmd1 == "merge"
|
585
|
-
merger = ::Coopy::Merger.new(parent,a,b
|
665
|
+
merger = ::Coopy::Merger.new(parent,a,b,@flags)
|
586
666
|
conflicts = merger.apply
|
587
667
|
ok = conflicts == 0
|
588
668
|
io.write_stderr(_hx_str(conflicts) + " conflict" + _hx_str((((conflicts > 1) ? "s" : ""))) + "\n") if conflicts > 0
|
@@ -590,12 +670,7 @@ module Coopy
|
|
590
670
|
elsif cmd1 == "trim"
|
591
671
|
tool.save_table(output,a)
|
592
672
|
elsif cmd1 == "render"
|
593
|
-
|
594
|
-
renderer.use_pretty_arrows(pretty)
|
595
|
-
renderer.render(a)
|
596
|
-
renderer.complete_html if !fragment
|
597
|
-
tool.save_text(output,renderer.html)
|
598
|
-
tool.save_text(css_output,renderer.sample_css) if css_output != nil
|
673
|
+
self.render_table(output,a)
|
599
674
|
elsif cmd1 == "copy"
|
600
675
|
tool.save_table(output,a)
|
601
676
|
end
|
@@ -610,7 +685,38 @@ module Coopy
|
|
610
685
|
class << self
|
611
686
|
attr_accessor :version
|
612
687
|
end
|
613
|
-
@version = "1.
|
688
|
+
@version = "1.3.1"
|
689
|
+
|
690
|
+
def Coopy.diff_as_html(local,remote,flags = nil)
|
691
|
+
o = ::Coopy::Coopy.diff(local,remote,flags)
|
692
|
+
render = ::Coopy::DiffRender.new
|
693
|
+
render.render(o).html
|
694
|
+
end
|
695
|
+
|
696
|
+
def Coopy.diff_as_ansi(local,remote,flags = nil)
|
697
|
+
o = ::Coopy::Coopy.diff(local,remote,flags)
|
698
|
+
render = ::Coopy::TerminalDiffRender.new
|
699
|
+
render.render(o)
|
700
|
+
end
|
701
|
+
|
702
|
+
def Coopy.diff(local,remote,flags = nil)
|
703
|
+
comp = ::Coopy::TableComparisonState.new
|
704
|
+
comp.a = local
|
705
|
+
comp.b = remote
|
706
|
+
flags = ::Coopy::CompareFlags.new if flags == nil
|
707
|
+
comp.compare_flags = flags
|
708
|
+
ct = ::Coopy::CompareTable.new(comp)
|
709
|
+
align = ct.align
|
710
|
+
td = ::Coopy::TableDiff.new(align,flags)
|
711
|
+
o = ::Coopy::SimpleTable.new(0,0)
|
712
|
+
td.hilite(o)
|
713
|
+
o
|
714
|
+
end
|
715
|
+
|
716
|
+
def Coopy.patch(local,patch,flags = nil)
|
717
|
+
patcher = ::Coopy::HighlightPatch.new(local,patch)
|
718
|
+
patcher.apply
|
719
|
+
end
|
614
720
|
|
615
721
|
def Coopy.compare_tables(local,remote,flags = nil)
|
616
722
|
comp = ::Coopy::TableComparisonState.new
|
@@ -618,7 +724,7 @@ module Coopy
|
|
618
724
|
comp.b = remote
|
619
725
|
comp.compare_flags = flags
|
620
726
|
ct = ::Coopy::CompareTable.new(comp)
|
621
|
-
|
727
|
+
ct
|
622
728
|
end
|
623
729
|
|
624
730
|
def Coopy.compare_tables3(parent,local,remote,flags = nil)
|
@@ -628,7 +734,7 @@ module Coopy
|
|
628
734
|
comp.b = remote
|
629
735
|
comp.compare_flags = flags
|
630
736
|
ct = ::Coopy::CompareTable.new(comp)
|
631
|
-
|
737
|
+
ct
|
632
738
|
end
|
633
739
|
|
634
740
|
# protected - in ruby this doesn't play well with static/inline methods
|
@@ -643,12 +749,12 @@ module Coopy
|
|
643
749
|
hp = ::Coopy::HighlightPatch.new(nil,nil)
|
644
750
|
csv = ::Coopy::Csv.new
|
645
751
|
tm = ::Coopy::TableModifier.new(nil)
|
646
|
-
sc = ::Coopy::SqlCompare.new(nil,nil,nil)
|
647
|
-
|
752
|
+
sc = ::Coopy::SqlCompare.new(nil,nil,nil,nil)
|
753
|
+
0
|
648
754
|
end
|
649
755
|
|
650
756
|
def Coopy.cell_for(x)
|
651
|
-
|
757
|
+
x
|
652
758
|
end
|
653
759
|
|
654
760
|
def Coopy.json_to_table(json)
|
@@ -705,7 +811,7 @@ module Coopy
|
|
705
811
|
end
|
706
812
|
end
|
707
813
|
output.trim_blank if output != nil
|
708
|
-
|
814
|
+
output
|
709
815
|
end
|
710
816
|
|
711
817
|
public
|
@@ -713,7 +819,7 @@ module Coopy
|
|
713
819
|
def Coopy.main
|
714
820
|
io = ::Coopy::TableIO.new
|
715
821
|
coopy1 = ::Coopy::Coopy.new
|
716
|
-
|
822
|
+
coopy1.coopyhx(io)
|
717
823
|
end
|
718
824
|
|
719
825
|
# protected - in ruby this doesn't play well with static/inline methods
|
@@ -770,7 +876,7 @@ module Coopy
|
|
770
876
|
end
|
771
877
|
end
|
772
878
|
workbook["sheet"] = sheet
|
773
|
-
|
879
|
+
workbook
|
774
880
|
end
|
775
881
|
|
776
882
|
haxe_me ["coopy", "Coopy"]
|