blob: a252c71b368bfd713ceddebfef671f2ca60d4f5c (
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
33
34
35
36
37
38
39
40
41
42
43
|
# frozen_string_literal: true
require_relative 'action_file_executor'
# CLI class to handle command-line interface operations.
class CLI
# Initializes the CLI with command-line arguments.
#
# @param args [Array<String>] The command-line arguments.
def initialize(args)
@args = args
validate_arguments
end
# Runs the CLI, executing actions from the provided file.
#
# @return [void]
def run
file_path = @args[0]
action_file_executor = ActionFileExecutor.new(file_path)
action_file_executor.execute_actions
end
private
# Validates the command-line arguments.
#
# @return [void]
# @raise [SystemExit] if no arguments are provided or the file does not exist.
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
|