summaryrefslogtreecommitdiff
path: root/lib/cli.rb
blob: 308721245b69a5e85b6063d3d74c48f173cbf83d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# frozen_string_literal: true

require_relative 'action_file_executor'

class CLI
  def initialize(args)
    @args = args
    validate_arguments
  end

  def run
    file_path = @args[0]
    action_file_executor = ActionFileExecutor.new(file_path)
    action_file_executor.execute_actions
  end

  private

  def validate_arguments
    if @args.empty?
      puts 'Usage: family_tree <path/to/actions.txt>'
      puts 'Please provide the path to the actions file.'
      exit 1
    end

    file_path = @args[0]
    return if File.exist?(file_path)

    puts "Error: The file '#{file_path}' does not exist."
    exit 1
  end
end