summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorSzymon Szukalski <szymon@skas.io>2024-10-24 12:27:13 +1100
committerSzymon Szukalski <szymon@skas.io>2024-10-24 12:27:13 +1100
commit08534a8164699017aa847fef62602abf6ec59e8f (patch)
treea18b56a9ccb9bebc4e64814391935756e6a03b26 /lib
parent28722066aa4b03a1b981f14e375497940e9f40e4 (diff)
Add ActionFileExecutor and execute from CLI
- Updated tests to use tempfile - Implemented initial ActionFileExecutor tests
Diffstat (limited to 'lib')
-rw-r--r--lib/action_file_executor.rb26
-rw-r--r--lib/cli.rb5
2 files changed, 30 insertions, 1 deletions
diff --git a/lib/action_file_executor.rb b/lib/action_file_executor.rb
new file mode 100644
index 0000000..15d4f63
--- /dev/null
+++ b/lib/action_file_executor.rb
@@ -0,0 +1,26 @@
+# frozen_string_literal: true
+
+class ActionFileExecutor
+ def initialize(file_path)
+ @file_path = file_path
+ validate_file
+ end
+
+ def execute_actions
+ File.open(@file_path, 'r') do |file|
+ file.each_line do |line|
+ action, *params = line.split(' ')
+ puts "Executing action: #{action} with params: #{params.join(', ')}"
+ end
+ end
+ end
+
+ private
+
+ def validate_file
+ return if File.exist?(@file_path)
+
+ puts "Error: The file '#{@file_path}' does not exist."
+ exit 1
+ end
+end
diff --git a/lib/cli.rb b/lib/cli.rb
index f2b185d..3087212 100644
--- a/lib/cli.rb
+++ b/lib/cli.rb
@@ -1,5 +1,7 @@
# frozen_string_literal: true
+require_relative 'action_file_executor'
+
class CLI
def initialize(args)
@args = args
@@ -8,7 +10,8 @@ class CLI
def run
file_path = @args[0]
- puts "Running actions from file: #{file_path} against the family tree."
+ action_file_executor = ActionFileExecutor.new(file_path)
+ action_file_executor.execute_actions
end
private