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
- #creta2filt(expr, codingpath, file) ⇒ Object
- #diff(file1, file2) ⇒ Object
- #gitdiff(path, file1, hex1, mode1, file2, hex2, mode2) ⇒ Object
- #help ⇒ 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
253 254 255 |
# File 'lib/cli.rb', line 253 def self.exit_on_failure? true end |
Instance Method Details
#__print_version ⇒ Object
249 250 251 |
# File 'lib/cli.rb', line 249 def __print_version puts "v#{Dcm::VERSION}" end |
#begu2creta(expr, codingpath, file) ⇒ Object
76 77 78 79 80 81 82 83 |
# File 'lib/cli.rb', line 76 def begu2creta(expr, codingpath, file) filter = VariantFilter.new(expr) list = parse_file(file) puts Codinginfo.new(codingpath, filter) .unflatten_list(list) .to_dcm end |
#cat(file = nil) ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/cli.rb', line 114 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
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/cli.rb', line 163 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
56 57 58 59 60 61 62 63 |
# File 'lib/cli.rb', line 56 def creta2begu(expr, codingpath, file) filter = VariantFilter.new(expr) list = parse_file(file) puts Codinginfo.new(codingpath, filter) .flatten_list(list) .to_dcm end |
#creta2filt(expr, codingpath, file) ⇒ Object
66 67 68 69 70 71 72 73 |
# File 'lib/cli.rb', line 66 def creta2filt(expr, codingpath, file) filter = VariantFilter.new(expr) list = parse_file(file) puts Codinginfo.new(codingpath, filter) .filter_list(list) .to_dcm end |
#diff(file1, file2) ⇒ Object
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
# File 'lib/cli.rb', line 203 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
190 191 192 193 194 195 196 |
# File 'lib/cli.rb', line 190 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 |
#help ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/cli.rb', line 24 def help super puts <<~EOS Options: FILTER may be any of the following keys: #{VariantFilter::ALLOWED_FILTERKEYS.join(", ")} and should have the format key:value EOS end |
#list(file = nil) ⇒ Object
87 88 89 90 91 |
# File 'lib/cli.rb', line 87 def list(file=nil) display_list(list: parse_file(file), detail: false, format: ([:lab] ? :lab : :tty)) end |
#liveview(file = nil) ⇒ Object
50 51 52 53 |
# File 'lib/cli.rb', line 50 def liveview(file=nil) list = parse_file(file) loop { LabelSelector.choose_from(list) } end |
#merge(*files) ⇒ Object
236 237 238 239 240 241 242 243 244 |
# File 'lib/cli.rb', line 236 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
41 42 43 44 45 46 47 |
# File 'lib/cli.rb', line 41 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
141 142 143 144 145 146 147 148 149 |
# File 'lib/cli.rb', line 141 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
35 36 37 |
# File 'lib/cli.rb', line 35 def show(file=nil) display_list(list: parse_file(file), detail: [:oneline] ? :onelinefull : true) end |
#size(file) ⇒ Object
229 230 231 232 |
# File 'lib/cli.rb', line 229 def size(file) list = parse_file(file) puts Filesize.new(list.map(&:bytesize).reduce(:+)).pretty end |
#summary(file = nil) ⇒ Object
95 96 97 98 99 100 101 102 103 |
# File 'lib/cli.rb', line 95 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
152 153 154 |
# File 'lib/cli.rb', line 152 def validate(file=nil) parse_file(file) end |