Class: Dcm::CLI
Class Method Summary collapse
Instance Method Summary collapse
- #__print_version ⇒ Object
- #begu2creta(expr, codingpath, file) ⇒ Object
- #cat(file = nil) ⇒ Object
- #compare(file1, file2) ⇒ Object
- #creta2begu(expr, codingpath, file) ⇒ Object
- #diff(file1, file2) ⇒ Object
- #gitdiff(path, file1, hex1, mode1, file2, hex2, mode2) ⇒ Object
- #list(file = nil) ⇒ Object
- #liveview(file = nil) ⇒ Object
- #merge(*files) ⇒ Object
- #new(*spec) ⇒ Object
- #rename(mapping = nil, file = nil) ⇒ Object
- #show(file = nil) ⇒ Object
- #size(file) ⇒ Object
- #summary(file = nil) ⇒ Object
- #validate(file = nil) ⇒ Object
Class Method Details
.exit_on_failure? ⇒ Boolean
230 231 232 |
# File 'lib/cli.rb', line 230 def self.exit_on_failure? true end |
Instance Method Details
#__print_version ⇒ Object
226 227 228 |
# File 'lib/cli.rb', line 226 def __print_version puts "v#{Dcm::VERSION}" end |
#begu2creta(expr, codingpath, file) ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/cli.rb', line 54 def begu2creta(expr, codingpath, file) list = parse_file(file) puts Codinginfo.new(codingpath, VariantFilter.new(expr)) .unflatten_list(list) .to_dcm end |
#cat(file = nil) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/cli.rb', line 91 def cat(file=nil) list = parse_file(file) if [:include] != ".*" || [:reject] != "(?!x)x" selector = Regexp.new([:include], true) rejector = Regexp.new([:reject], true) list = list. select { |l| l.match(selector) }. reject { |l| l.match(rejector) } end if [:inlab].present? labfile = Ecu::LabelList.from_lab(File.read([:inlab])) list = list.select { |l| labfile.any? { |s| s.name == l.name } } end if [:notinlab].present? labfile = Ecu::LabelList.from_lab(File.read([:notinlab])) list = list.reject { |l| labfile.any? { |s| s.name == l.name } } end list.headers += [:headers] list.subheaders += [:subheaders] if [:mfile] puts list.to_mfile else puts list.to_dcm([:indented]) end end |
#compare(file1, file2) ⇒ Object
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/cli.rb', line 140 def compare(file1, file2) comparison = render_comparison(file1, file2, precision: [:precision]) if [:left] puts to_lab(comparison.names(:left_exclusive)) elsif [:right] puts to_lab(comparison.names(:right_exclusive)) elsif [:equal] puts to_lab(comparison.names(:equal)) elsif [:unequal] puts to_lab(comparison.names(:nonequal)) elsif [:comparable] puts ( comparison.names(:equal).map { |l| "#{l}: equal".colorize(:green) } + comparison.names(:nonequal).map { |l| "#{l}: unequal".colorize(:red) } ) else puts "#{comparison.names(:left_exclusive).size.quantify("label")} exclusive to #{file1}" puts "#{comparison.names(:right_exclusive).size.quantify("label")} exclusive to #{file2}" puts "#{comparison.names(:common).size.quantify("label")} comparable" puts " #{comparison.names(:equal).size.quantify("label")} equal".colorize(:green) puts " #{comparison.names(:nonequal).size.quantify("label")} unequal".colorize(:red) puts "DCMs are identical!".colorize(:green) if comparison.identical? end end |
#creta2begu(expr, codingpath, file) ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/cli.rb', line 45 def creta2begu(expr, codingpath, file) list = parse_file(file) puts Codinginfo.new(codingpath, VariantFilter.new(expr)) .flatten_list(list) .to_dcm end |
#diff(file1, file2) ⇒ Object
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/cli.rb', line 180 def diff(file1, file2) comparison = render_comparison(file1, file2, precision: [:precision]) showall = !([:left] || [:comparable] || [:right]) puts "-#{file1}".colorize(:red) puts "+#{file2}".colorize(:green) puts "" if [:left] || showall comparison.left_exclusive.each do |label| puts DiffViewer.new(label.to_s(detail: true), "") end end if [:comparable] || showall comparison.differences.each do |left, right| puts DiffViewer.new(left.to_s(detail: true), right.to_s(detail: true)) end end if [:right] || showall comparison.right_exclusive.each do |label| puts DiffViewer.new("", label.to_s(detail: true)) end end end |
#gitdiff(path, file1, hex1, mode1, file2, hex2, mode2) ⇒ Object
167 168 169 170 171 172 173 |
# File 'lib/cli.rb', line 167 def gitdiff(path, file1, hex1, mode1, file2, hex2, mode2) if [file1, file2].all? { |f| File.extname(f).downcase == ".dcm" } invoke(:diff, [file1, file2]) else puts DiffViewer.new(File.read(file1), File.read(file2)) end end |
#list(file = nil) ⇒ Object
64 65 66 67 68 |
# File 'lib/cli.rb', line 64 def list(file=nil) display_list(list: parse_file(file), detail: false, format: ([:lab] ? :lab : :tty)) end |
#liveview(file = nil) ⇒ Object
39 40 41 42 |
# File 'lib/cli.rb', line 39 def liveview(file=nil) list = parse_file(file) loop { LabelSelector.choose_from(list) } end |
#merge(*files) ⇒ Object
213 214 215 216 217 218 219 220 221 |
# File 'lib/cli.rb', line 213 def merge(*files) baselist = parse_file(files.shift) while not files.empty? mergelist = parse_file(files.shift) baselist = Ecu::LabelListComparison.new(baselist, mergelist). merge(priority: [:priority].downcase.to_sym) end puts baselist.to_dcm([:indented]) end |
#new(*spec) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/cli.rb', line 30 def new(*spec) list = parse_spec(spec) puts list.to_dcm(option[:indented]) rescue RuntimeError => e puts e. exit 1 end |
#rename(mapping = nil, file = nil) ⇒ Object
118 119 120 121 122 123 124 125 126 |
# File 'lib/cli.rb', line 118 def rename(mapping=nil, file=nil) list = parse_file(file) mappings = JSON.parse(FileReader.read(mapping)) list = list.map_int do |label| label.with \ name: mappings.filter_map { |m| m["new"] if m["old"] == label.name }&.first || label.name end puts list.to_dcm([:indented]) end |
#show(file = nil) ⇒ Object
24 25 26 |
# File 'lib/cli.rb', line 24 def show(file=nil) display_list(list: parse_file(file), detail: [:oneline] ? :onelinefull : true) end |
#size(file) ⇒ Object
206 207 208 209 |
# File 'lib/cli.rb', line 206 def size(file) list = parse_file(file) puts Filesize.new(list.map(&:bytesize).reduce(:+)).pretty end |
#summary(file = nil) ⇒ Object
72 73 74 75 76 77 78 79 80 |
# File 'lib/cli.rb', line 72 def summary(file=nil) list = parse_file(file) puts "DCM file with #{list.count.quantify("label")}" if [:verbose] list.group_by(&:function).each do |function, labels| puts " #{function}: #{labels.count}" end end end |
#validate(file = nil) ⇒ Object
129 130 131 |
# File 'lib/cli.rb', line 129 def validate(file=nil) parse_file(file) end |