daff 1.3.2 → 1.3.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -25,6 +25,7 @@ module Coopy
25
25
  @parent = nil
26
26
  @count_like_a_spreadsheet = true
27
27
  @ignore_whitespace = false
28
+ @ignore_case = false
28
29
  end
29
30
 
30
31
  attr_accessor :ordered
@@ -42,11 +43,13 @@ module Coopy
42
43
  attr_accessor :allow_nested_cells
43
44
  attr_accessor :warnings
44
45
  attr_accessor :diff_strategy
46
+ attr_accessor :padding_strategy
45
47
  attr_accessor :show_meta
46
48
  attr_accessor :show_unchanged_meta
47
49
  attr_accessor :parent
48
50
  attr_accessor :count_like_a_spreadsheet
49
51
  attr_accessor :ignore_whitespace
52
+ attr_accessor :ignore_case
50
53
 
51
54
  def filter(act,allow)
52
55
  if @acts == nil
@@ -36,6 +36,8 @@ module Coopy
36
36
  end
37
37
  alignment = ::Coopy::Alignment.new
38
38
  self.align_core(alignment)
39
+ alignment.comp = @comp
40
+ @comp.alignment = alignment
39
41
  alignment
40
42
  end
41
43
 
@@ -59,7 +61,11 @@ module Coopy
59
61
  tab2 = @comp.b
60
62
  tab3 = @comp.a
61
63
  end
62
- sc = ::Coopy::SqlCompare.new(tab1.get_database,tab1,tab2,tab3,align)
64
+ db = nil
65
+ db = tab1.get_database if tab1 != nil
66
+ db = tab2.get_database if db == nil && tab2 != nil
67
+ db = tab3.get_database if db == nil && tab3 != nil
68
+ sc = ::Coopy::SqlCompare.new(db,tab1,tab2,tab3,align)
63
69
  sc.apply
64
70
  align.meta.reference = align.reference.meta if @comp.p != nil
65
71
  return
@@ -588,6 +594,22 @@ module Coopy
588
594
  p = @comp.p
589
595
  a = @comp.a
590
596
  b = @comp.b
597
+ @comp.get_meta
598
+ nested = false
599
+ if @comp.p_meta != nil
600
+ nested = true if @comp.p_meta.is_nested
601
+ end
602
+ if @comp.a_meta != nil
603
+ nested = true if @comp.a_meta.is_nested
604
+ end
605
+ if @comp.b_meta != nil
606
+ nested = true if @comp.b_meta.is_nested
607
+ end
608
+ if nested
609
+ @comp.is_equal = false
610
+ @comp.is_equal_known = true
611
+ return true
612
+ end
591
613
  eq = self.is_equal2(a,b)
592
614
  eq = self.is_equal2(p,a) if eq && p != nil
593
615
  @comp.is_equal = eq
@@ -640,7 +662,21 @@ module Coopy
640
662
 
641
663
  def use_sql
642
664
  return false if @comp.compare_flags == nil
643
- @comp.compare_flags.diff_strategy == "sql"
665
+ @comp.get_meta
666
+ sql = true
667
+ if @comp.p_meta != nil
668
+ sql = false if !@comp.p_meta.is_sql
669
+ end
670
+ if @comp.a_meta != nil
671
+ sql = false if !@comp.a_meta.is_sql
672
+ end
673
+ if @comp.b_meta != nil
674
+ sql = false if !@comp.b_meta.is_sql
675
+ end
676
+ sql = false if @comp.p != nil && @comp.p_meta == nil
677
+ sql = false if @comp.a != nil && @comp.a_meta == nil
678
+ sql = false if @comp.b != nil && @comp.b_meta == nil
679
+ sql
644
680
  end
645
681
 
646
682
  haxe_me ["coopy", "CompareTable"]
@@ -87,10 +87,13 @@ module Coopy
87
87
  @extern_preference = true
88
88
  end
89
89
 
90
- def render_table(name,t)
90
+ def get_renderer
91
91
  renderer = ::Coopy::DiffRender.new
92
92
  renderer.use_pretty_arrows(@pretty)
93
- renderer.render(t)
93
+ renderer
94
+ end
95
+
96
+ def apply_renderer(name,renderer)
94
97
  renderer.complete_html if !@fragment
95
98
  if @format_preference == "www"
96
99
  @io.send_to_browser(renderer.html)
@@ -101,24 +104,88 @@ module Coopy
101
104
  true
102
105
  end
103
106
 
104
- def save_table(name,t)
107
+ def render_table(name,t)
108
+ renderer = self.get_renderer
109
+ renderer.render(t)
110
+ self.apply_renderer(name,renderer)
111
+ end
112
+
113
+ def render_tables(name,t)
114
+ renderer = self.get_renderer
115
+ renderer.render_tables(t)
116
+ self.apply_renderer(name,renderer)
117
+ end
118
+
119
+ def save_table(name,t,render = nil)
120
+ txt = self.encode_table(name,t,render)
121
+ self.save_text(name,txt)
122
+ end
123
+
124
+ def encode_table(name,t,render = nil)
105
125
  self.set_format(@output_format) if @output_format != "copy"
106
126
  txt = ""
107
127
  self.check_format(name)
108
128
  @format_preference = "csv" if @format_preference == "sqlite" && !@extern_preference
109
- if @format_preference == "csv"
110
- csv = ::Coopy::Csv.new(@delim_preference)
111
- txt = csv.render_table(t)
112
- elsif @format_preference == "ndjson"
113
- txt = ::Coopy::Ndjson.new(t).render
114
- elsif @format_preference == "html" || @format_preference == "www"
115
- return self.render_table(name,t)
116
- elsif @format_preference == "sqlite"
117
- @io.write_stderr("! Cannot yet output to sqlite, aborting\n")
118
- return false
129
+ if render == nil
130
+ if @format_preference == "csv"
131
+ csv = ::Coopy::Csv.new(@delim_preference)
132
+ txt = csv.render_table(t)
133
+ elsif @format_preference == "ndjson"
134
+ txt = ::Coopy::Ndjson.new(t).render
135
+ elsif @format_preference == "html" || @format_preference == "www"
136
+ self.render_table(name,t)
137
+ elsif @format_preference == "sqlite"
138
+ @io.write_stderr("! Cannot yet output to sqlite, aborting\n")
139
+ return ""
140
+ else
141
+ value = ::Coopy::Coopy.jsonify(t)
142
+ txt = ::Haxe::Format::JsonPrinter._print(value,nil," ")
143
+ end
119
144
  else
120
- value = ::Coopy::Coopy.jsonify(t)
121
- txt = ::Haxe::Format::JsonPrinter._print(value,nil," ")
145
+ txt = render.render(t)
146
+ end
147
+ txt
148
+ end
149
+
150
+ def save_tables(name,os,use_color)
151
+ self.set_format(@output_format) if @output_format != "copy"
152
+ txt = ""
153
+ self.check_format(name)
154
+ render = nil
155
+ render = ::Coopy::TerminalDiffRender.new(@flags) if use_color
156
+ order = os.get_order
157
+ return self.save_table(name,os.one,render) if order.length == 1
158
+ return self.render_tables(name,os) if @format_preference == "html" || @format_preference == "www"
159
+ need_blank = false
160
+ if order.length == 0 || os.has_ins_del
161
+ txt += self.encode_table(name,os.one,render)
162
+ need_blank = true
163
+ end
164
+ if order.length > 1
165
+ _g1 = 1
166
+ _g = order.length
167
+ while(_g1 < _g)
168
+ i = _g1
169
+ _g1+=1
170
+ t = os.get(order[i])
171
+ if t != nil
172
+ txt += "\n" if need_blank
173
+ need_blank = true
174
+ txt += _hx_str(order[i]) + "\n"
175
+ line = ""
176
+ begin
177
+ _g3 = 0
178
+ _g2 = order[i].length
179
+ while(_g3 < _g2)
180
+ i1 = _g3
181
+ _g3+=1
182
+ line += "="
183
+ end
184
+ end
185
+ txt += _hx_str(line) + "\n"
186
+ txt += self.encode_table(name,os.get(order[i]),render)
187
+ end
188
+ end
122
189
  end
123
190
  self.save_text(name,txt)
124
191
  end
@@ -132,6 +199,69 @@ module Coopy
132
199
  true
133
200
  end
134
201
 
202
+ def json_to_tables(json)
203
+ tables = Reflect.field(json,"tables")
204
+ return self.json_to_table(json) if tables == nil
205
+ ::Coopy::JsonTables.new(json,@flags)
206
+ end
207
+
208
+ def json_to_table(json)
209
+ output = nil
210
+ begin
211
+ _g = 0
212
+ _g1 = Reflect.fields(json)
213
+ while(_g < _g1.length)
214
+ name = _g1[_g]
215
+ _g+=1
216
+ t = Reflect.field(json,name)
217
+ columns = Reflect.field(t,"columns")
218
+ next if columns == nil
219
+ rows = Reflect.field(t,"rows")
220
+ next if rows == nil
221
+ output = ::Coopy::SimpleTable.new(columns.length,rows.length)
222
+ has_hash = false
223
+ has_hash_known = false
224
+ begin
225
+ _g3 = 0
226
+ _g2 = rows.length
227
+ while(_g3 < _g2)
228
+ i = _g3
229
+ _g3+=1
230
+ row = rows[i]
231
+ if !has_hash_known
232
+ has_hash = true if Reflect.fields(row).length == columns.length
233
+ has_hash_known = true
234
+ end
235
+ if !has_hash
236
+ lst = row
237
+ begin
238
+ _g5 = 0
239
+ _g4 = columns.length
240
+ while(_g5 < _g4)
241
+ j = _g5
242
+ _g5+=1
243
+ val = lst[j]
244
+ output.set_cell(j,i,::Coopy::Coopy.cell_for(val))
245
+ end
246
+ end
247
+ else
248
+ _g51 = 0
249
+ _g41 = columns.length
250
+ while(_g51 < _g41)
251
+ j1 = _g51
252
+ _g51+=1
253
+ val1 = Reflect.field(row,columns[j1])
254
+ output.set_cell(j1,i,::Coopy::Coopy.cell_for(val1))
255
+ end
256
+ end
257
+ end
258
+ end
259
+ end
260
+ end
261
+ output.trim_blank if output != nil
262
+ output
263
+ end
264
+
135
265
  def load_table(name)
136
266
  ext = self.check_format(name)
137
267
  if ext == "sqlite"
@@ -140,25 +270,7 @@ module Coopy
140
270
  @io.write_stderr("! Cannot open database, aborting\n")
141
271
  return nil
142
272
  end
143
- helper = ::Coopy::SqliteHelper.new
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
159
- end
160
- tab = ::Coopy::SqlTable.new(sql,::Coopy::SqlTableName.new(name1),helper)
161
- @strategy = "sql"
273
+ tab = ::Coopy::SqlTables.new(sql,@flags)
162
274
  return tab
163
275
  end
164
276
  txt = @io.get_content(name)
@@ -171,7 +283,7 @@ module Coopy
171
283
  begin
172
284
  json = ::Haxe::Format::JsonParser.new(txt).parse_rec
173
285
  @format_preference = "json"
174
- t1 = ::Coopy::Coopy.json_to_table(json)
286
+ t1 = self.json_to_tables(json)
175
287
  raise hx_raise("JSON failed") if t1 == nil
176
288
  return t1
177
289
  rescue => e
@@ -504,6 +616,16 @@ module Coopy
504
616
  @flags.ignore_whitespace = true
505
617
  args.slice!(i,1)
506
618
  break
619
+ elsif tag == "-i" || tag == "--ignore-case"
620
+ more = true
621
+ @flags.ignore_case = true
622
+ args.slice!(i,1)
623
+ break
624
+ elsif tag == "--padding"
625
+ more = true
626
+ @flags.padding_strategy = args[i + 1]
627
+ args.slice!(i,2)
628
+ break
507
629
  end
508
630
  end
509
631
  end
@@ -570,9 +692,11 @@ module Coopy
570
692
  io.write_stderr(" --no-color: make sure terminal colors are not used\n")
571
693
  io.write_stderr(" --ordered: assume row order is meaningful (default for CSV)\n")
572
694
  io.write_stderr(" --output-format [csv|tsv|ssv|json|copy|html]: set format for output\n")
695
+ io.write_stderr(" --padding [dense|sparse|smart]: set padding method for aligning columns\n")
573
696
  io.write_stderr(" --table NAME: compare the named table, used with SQL sources\n")
574
697
  io.write_stderr(" --unordered: assume row order is meaningless (default for json formats)\n")
575
698
  io.write_stderr(" -w / --ignore-whitespace: ignore changes in leading/trailing whitespace\n")
699
+ io.write_stderr(" -i / --ignore-case: ignore differences in case\n")
576
700
  io.write_stderr("\n")
577
701
  io.write_stderr(" daff render [--output OUTPUT.html] [--css CSS.css] [--fragment] [--plain] diff.csv\n")
578
702
  io.write_stderr(" --css CSS.css: generate a suitable css file to go with the html\n")
@@ -650,19 +774,15 @@ module Coopy
650
774
  align = ct1.align
651
775
  td = ::Coopy::TableDiff.new(align,@flags)
652
776
  o = ::Coopy::SimpleTable.new(0,0)
653
- td.hilite(o)
777
+ os = ::Coopy::Tables.new(o)
778
+ td.hilite_with_nesting(os)
654
779
  use_color = color
655
780
  if !(color || no_color)
656
781
  if output == "-" && @output_format == "copy"
657
782
  use_color = io.is_tty if io.is_tty_known
658
783
  end
659
784
  end
660
- if use_color
661
- render = ::Coopy::TerminalDiffRender.new
662
- tool.save_text(output,render.render(o))
663
- else
664
- tool.save_table(output,o)
665
- end
785
+ tool.save_tables(output,os,use_color)
666
786
  elsif cmd1 == "patch"
667
787
  patcher = ::Coopy::HighlightPatch.new(a,b)
668
788
  patcher.apply
@@ -691,7 +811,7 @@ module Coopy
691
811
  class << self
692
812
  attr_accessor :version
693
813
  end
694
- @version = "1.3.2"
814
+ @version = "1.3.6"
695
815
 
696
816
  def Coopy.diff_as_html(local,remote,flags = nil)
697
817
  o = ::Coopy::Coopy.diff(local,remote,flags)
@@ -701,33 +821,36 @@ module Coopy
701
821
 
702
822
  def Coopy.diff_as_ansi(local,remote,flags = nil)
703
823
  o = ::Coopy::Coopy.diff(local,remote,flags)
704
- render = ::Coopy::TerminalDiffRender.new
824
+ render = ::Coopy::TerminalDiffRender.new(flags)
705
825
  render.render(o)
706
826
  end
707
827
 
708
828
  def Coopy.diff(local,remote,flags = nil)
709
829
  comp = ::Coopy::TableComparisonState.new
710
- comp.a = local
711
- comp.b = remote
830
+ comp.a = ::Coopy::Coopy.tablify(local)
831
+ comp.b = ::Coopy::Coopy.tablify(remote)
712
832
  flags = ::Coopy::CompareFlags.new if flags == nil
713
833
  comp.compare_flags = flags
714
834
  ct = ::Coopy::CompareTable.new(comp)
715
835
  align = ct.align
716
836
  td = ::Coopy::TableDiff.new(align,flags)
717
- o = ::Coopy::SimpleTable.new(0,0)
837
+ o = nil
838
+ o = comp.a.create if comp.a != nil
839
+ o = comp.b.create if o == nil && comp.b != nil
840
+ o = ::Coopy::SimpleTable.new(0,0) if o == nil
718
841
  td.hilite(o)
719
842
  o
720
843
  end
721
844
 
722
845
  def Coopy.patch(local,patch,flags = nil)
723
- patcher = ::Coopy::HighlightPatch.new(local,patch)
846
+ patcher = ::Coopy::HighlightPatch.new(::Coopy::Coopy.tablify(local),::Coopy::Coopy.tablify(patch))
724
847
  patcher.apply
725
848
  end
726
849
 
727
850
  def Coopy.compare_tables(local,remote,flags = nil)
728
851
  comp = ::Coopy::TableComparisonState.new
729
- comp.a = local
730
- comp.b = remote
852
+ comp.a = ::Coopy::Coopy.tablify(local)
853
+ comp.b = ::Coopy::Coopy.tablify(remote)
731
854
  comp.compare_flags = flags
732
855
  ct = ::Coopy::CompareTable.new(comp)
733
856
  ct
@@ -735,9 +858,9 @@ module Coopy
735
858
 
736
859
  def Coopy.compare_tables3(parent,local,remote,flags = nil)
737
860
  comp = ::Coopy::TableComparisonState.new
738
- comp.p = parent
739
- comp.a = local
740
- comp.b = remote
861
+ comp.p = ::Coopy::Coopy.tablify(parent)
862
+ comp.a = ::Coopy::Coopy.tablify(local)
863
+ comp.b = ::Coopy::Coopy.tablify(remote)
741
864
  comp.compare_flags = flags
742
865
  ct = ::Coopy::CompareTable.new(comp)
743
866
  ct
@@ -756,6 +879,9 @@ module Coopy
756
879
  csv = ::Coopy::Csv.new
757
880
  tm = ::Coopy::TableModifier.new(nil)
758
881
  sc = ::Coopy::SqlCompare.new(nil,nil,nil,nil)
882
+ sq = ::Coopy::SqliteHelper.new
883
+ sm = ::Coopy::SimpleMeta.new(nil)
884
+ ct = ::Coopy::CombinedTable.new(nil)
759
885
  0
760
886
  end
761
887
 
@@ -763,63 +889,6 @@ module Coopy
763
889
  x
764
890
  end
765
891
 
766
- def Coopy.json_to_table(json)
767
- output = nil
768
- begin
769
- _g = 0
770
- _g1 = Reflect.fields(json)
771
- while(_g < _g1.length)
772
- name = _g1[_g]
773
- _g+=1
774
- t = Reflect.field(json,name)
775
- columns = Reflect.field(t,"columns")
776
- next if columns == nil
777
- rows = Reflect.field(t,"rows")
778
- next if rows == nil
779
- output = ::Coopy::SimpleTable.new(columns.length,rows.length)
780
- has_hash = false
781
- has_hash_known = false
782
- begin
783
- _g3 = 0
784
- _g2 = rows.length
785
- while(_g3 < _g2)
786
- i = _g3
787
- _g3+=1
788
- row = rows[i]
789
- if !has_hash_known
790
- has_hash = true if Reflect.fields(row).length == columns.length
791
- has_hash_known = true
792
- end
793
- if !has_hash
794
- lst = row
795
- begin
796
- _g5 = 0
797
- _g4 = columns.length
798
- while(_g5 < _g4)
799
- j = _g5
800
- _g5+=1
801
- val = lst[j]
802
- output.set_cell(j,i,::Coopy::Coopy.cell_for(val))
803
- end
804
- end
805
- else
806
- _g51 = 0
807
- _g41 = columns.length
808
- while(_g51 < _g41)
809
- j1 = _g51
810
- _g51+=1
811
- val1 = Reflect.field(row,columns[j1])
812
- output.set_cell(j1,i,::Coopy::Coopy.cell_for(val1))
813
- end
814
- end
815
- end
816
- end
817
- end
818
- end
819
- output.trim_blank if output != nil
820
- output
821
- end
822
-
823
892
  public
824
893
 
825
894
  def Coopy.main
@@ -885,6 +954,15 @@ module Coopy
885
954
  workbook
886
955
  end
887
956
 
957
+ public
958
+
959
+ def Coopy.tablify(data)
960
+ return data if data == nil
961
+ return data if data.respond_to? :get_cell_view
962
+ require 'ruby_table_view' unless defined?(RubyTableView)
963
+ ::RubyTableView.new(data)
964
+ end
965
+
888
966
  haxe_me ["coopy", "Coopy"]
889
967
  end
890
968