Class: Cabriolet::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/cabriolet/cli.rb

Overview

CLI provides unified command-line interface for Cabriolet

The CLI uses auto-detection to determine the format of input files, then dispatches commands to the appropriate format handler. A –format option allows manual override when needed.

Legacy format-specific commands are maintained for backward compatibility.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.exit_on_failure?Boolean



35
36
37
# File 'lib/cabriolet/cli.rb', line 35

def self.exit_on_failure?
  true
end

Instance Method Details

#chm_create(output, *files) ⇒ Object



185
186
187
188
189
# File 'lib/cabriolet/cli.rb', line 185

def chm_create(output, *files)
  opts = { verbose: options[:verbose], window_bits: options[:window_bits],
           format: :chm }
  run_dispatcher(:create, output, files, **opts)
end

#chm_extract(file, output_dir = nil) ⇒ Object



166
167
168
169
# File 'lib/cabriolet/cli.rb', line 166

def chm_extract(file, output_dir = nil)
  opts = { verbose: options[:verbose], output: options[:output] }
  run_with_format(:extract, :chm, file, output_dir, **opts)
end

#chm_info(file) ⇒ Object



175
176
177
# File 'lib/cabriolet/cli.rb', line 175

def chm_info(file)
  run_with_format(:info, :chm, file, verbose: options[:verbose])
end

#chm_list(file) ⇒ Object



157
158
159
# File 'lib/cabriolet/cli.rb', line 157

def chm_list(file)
  run_with_format(:list, :chm, file, verbose: options[:verbose])
end

#compress(file, output = nil) ⇒ Object



220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
# File 'lib/cabriolet/cli.rb', line 220

def compress(file, output = nil)
  # SZDD format option refers to SZDD variant (normal/qbasic), not file format
  # File format is always :szdd, variant is passed as szdd_format
  szdd_variant = options[:format] || "normal"

  opts = {
    verbose: options[:verbose],
    output: options[:output],
    format: :szdd, # Always SZDD format
    szdd_format: szdd_variant.to_sym, # Pass variant as szdd_format
    missing_char: options[:missing_char],
  }
  # SZDD convention: auto-generate output name
  output ||= opts[:output]
  if output.nil?
    ext = File.extname(file)
    # SZDD format: last character of extension replaced with underscore
    # e.g., file.txt -> file.tx_, file.c -> file.c_
    if ext.length.between?(2, 4) # .c, .txt, .html, etc.
      base = File.basename(file, ext)
      output = "#{base}#{ext.chomp(ext[-1])}_"
    else
      output = "#{file}_"
    end
    opts[:output] = output
  end
  run_dispatcher(:create, output, [file], **opts)
end

#create(output, *files) ⇒ Object



97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/cabriolet/cli.rb', line 97

def create(output, *files)
  # Normalize options for create command
  create_options = normalize_create_options(options)

  # Detect format from output extension if not specified
  format = detect_format_from_output(output, create_options[:format])

  # Set the format in options for the dispatcher
  create_options[:format] = format

  run_dispatcher(:create, output, files, **create_options)
end

#expand(file, output = nil) ⇒ Object



197
198
199
200
201
202
# File 'lib/cabriolet/cli.rb', line 197

def expand(file, output = nil)
  # Use positional output if provided, otherwise use option
  final_output = output || options[:output]
  opts = { verbose: options[:verbose], output: final_output, format: :szdd }
  run_dispatcher(:extract, file, final_output, **opts)
end

#extract(file, output_dir = nil) ⇒ Object



68
69
70
# File 'lib/cabriolet/cli.rb', line 68

def extract(file, output_dir = nil)
  run_dispatcher(:extract, file, output_dir, **options)
end

#hlp_create(output, *files) ⇒ Object



322
323
324
325
326
327
328
329
330
331
332
333
# File 'lib/cabriolet/cli.rb', line 322

def hlp_create(output, *files)
  # Ensure format is set (default from Thor option or :hlp)
  format = options[:format] || :hlp

  opts = {
    verbose: options[:verbose],
    compress: options[:compress],
    format: format,
    hlp_format: options[:format],
  }
  run_dispatcher(:create, output, files, **opts)
end

#hlp_extract(file, output_dir = nil) ⇒ Object



301
302
303
304
305
# File 'lib/cabriolet/cli.rb', line 301

def hlp_extract(file, output_dir = nil)
  opts = { verbose: options[:verbose], output: options[:output],
           format: :hlp }
  run_dispatcher(:extract, file, output_dir, **opts)
end

#hlp_info(file) ⇒ Object



311
312
313
# File 'lib/cabriolet/cli.rb', line 311

def hlp_info(file)
  run_with_format(:info, :hlp, file, verbose: options[:verbose])
end

#info(file) ⇒ Object



113
114
115
# File 'lib/cabriolet/cli.rb', line 113

def info(file)
  run_dispatcher(:info, file, **options)
end

#kwaj_compress(file, output = nil) ⇒ Object



280
281
282
283
284
285
286
287
288
289
290
291
292
293
# File 'lib/cabriolet/cli.rb', line 280

def kwaj_compress(file, output = nil)
  # Use positional output if provided, otherwise use option or default
  output_file = output || options[:output] || "#{file}.kwj"
  opts = {
    verbose: options[:verbose],
    output: output_file,
    format: :kwaj,
    compression: options[:compression],
    include_length: options[:include_length],
    filename: options[:filename],
    extra_data: options[:extra_data],
  }
  run_dispatcher(:create, opts[:output], [file], **opts)
end

#kwaj_extract(file, output = nil) ⇒ Object



255
256
257
258
259
260
# File 'lib/cabriolet/cli.rb', line 255

def kwaj_extract(file, output = nil)
  # Use positional output if provided, otherwise use option
  output_file = output || options[:output]
  opts = { verbose: options[:verbose], output: output_file, format: :kwaj }
  run_dispatcher(:extract, file, nil, **opts)
end

#kwaj_info(file) ⇒ Object



266
267
268
# File 'lib/cabriolet/cli.rb', line 266

def kwaj_info(file)
  run_with_format(:info, :kwaj, file, verbose: options[:verbose])
end

#list(file) ⇒ Object



53
54
55
# File 'lib/cabriolet/cli.rb', line 53

def list(file)
  run_dispatcher(:list, file, **options)
end

#lit_create(output, *files) ⇒ Object



363
364
365
366
367
368
369
370
371
# File 'lib/cabriolet/cli.rb', line 363

def lit_create(output, *files)
  opts = {
    verbose: options[:verbose],
    compress: options[:compress],
    format: :lit,
    language_id: parse_language_id(options[:language_id]),
  }
  run_dispatcher(:create, output, files, **opts)
end

#lit_extract(file, output_dir = nil) ⇒ Object



341
342
343
344
345
# File 'lib/cabriolet/cli.rb', line 341

def lit_extract(file, output_dir = nil)
  opts = { verbose: options[:verbose], output: options[:output],
           format: :lit }
  run_dispatcher(:extract, file, output_dir, **opts)
end

#lit_info(file) ⇒ Object



351
352
353
# File 'lib/cabriolet/cli.rb', line 351

def lit_info(file)
  run_with_format(:info, :lit, file, verbose: options[:verbose])
end

#oab_create(input, output) ⇒ Object



403
404
405
406
407
408
409
410
411
# File 'lib/cabriolet/cli.rb', line 403

def oab_create(input, output)
  opts = {
    verbose: options[:verbose],
    format: :oab,
    block_size: options[:block_size],
    base_file: options[:base],
  }
  run_dispatcher(:create, output, [input], **opts)
end

#oab_extract(input, output) ⇒ Object



379
380
381
382
383
384
385
386
387
# File 'lib/cabriolet/cli.rb', line 379

def oab_extract(input, output)
  opts = {
    verbose: options[:verbose],
    output: output,
    format: :oab,
    base_file: options[:base],
  }
  run_dispatcher(:extract, input, nil, **opts)
end

#oab_info(file) ⇒ Object



393
394
395
# File 'lib/cabriolet/cli.rb', line 393

def oab_info(file)
  run_with_format(:info, :oab, file, verbose: options[:verbose])
end

#search(file) ⇒ Object



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/cabriolet/cli.rb', line 129

def search(file)
  setup_verbose(options[:verbose])

  decompressor = CAB::Decompressor.new
  cabinet = decompressor.search(file)

  if cabinet
    count = 0
    cab = cabinet
    while cab
      puts "Cabinet found at offset #{cab.base_offset}"
      puts "  Files: #{cab.file_count}, Folders: #{cab.folder_count}"
      cab = cab.next
      count += 1
    end
    puts "\nTotal: #{count} cabinet(s) found"
  else
    puts "No cabinets found in #{file}"
  end
rescue Error => e
  abort "Error: #{e.message}"
end

#szdd_info(file) ⇒ Object



208
209
210
# File 'lib/cabriolet/cli.rb', line 208

def szdd_info(file)
  run_with_format(:info, :szdd, file, verbose: options[:verbose])
end

#test(file) ⇒ Object



119
120
121
# File 'lib/cabriolet/cli.rb', line 119

def test(file)
  run_dispatcher(:test, file, **options)
end

#versionObject



414
415
416
# File 'lib/cabriolet/cli.rb', line 414

def version
  puts "Cabriolet version #{Cabriolet::VERSION}"
end