10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/group_by_match_type/cli.rb', line 10
def self.start(args)
if args.empty? || args.include?('-h') || args.include?('--help')
show_help
exit(args.empty? ? 1 : 0)
end
if args.length < 2 || args.length > 3
puts 'Error: Please provide the input file, matching type, and optionally an output file path'
show_help
exit 1
end
input_file, matching_type, output_file = args
unless VALID_TYPES.include?(matching_type)
puts "Error: Invalid matching type '#{matching_type}'"
show_help
exit 1
end
unless File.exist?(input_file)
puts "Error: File '#{input_file}' does not exist"
exit 1
end
begin
matcher = Matcher.new(input_file, matching_type)
output = matcher.process(output_file)
puts "Processing complete. Output written to: #{output}"
rescue StandardError => e
puts "Error: #{e.message}"
exit 1
end
end
|