Class: GroupByMatchType::CLI

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

Constant Summary collapse

VALID_TYPES =
%w[same_email same_phone same_email_or_phone].freeze

Class Method Summary collapse

Class Method Details

.show_helpObject



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/group_by_match_type/cli.rb', line 45

def self.show_help
  puts "    Usage: group_by_match_type INPUT_FILE MATCHING_TYPE [OUTPUT_FILE]\n\n    Arguments:\n      INPUT_FILE    Path to the CSV file to process\n      MATCHING_TYPE One of: same_email, same_phone, same_email_or_phone\n      OUTPUT_FILE   (Optional) Path to save the grouped CSV output\n\n    Example:\n      group_by_match_type contacts.csv same_email ~/Downloads/contacts_grouped.csv\n  HELP_MESSAGE\nend\n"

.start(args) ⇒ Object



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