summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSzymon Szukalski <szymon@skas.io>2024-10-24 11:32:34 +1100
committerSzymon Szukalski <szymon@skas.io>2024-10-24 11:32:34 +1100
commit1d1b3511e4c523458d78653cb8781a5328600387 (patch)
treef5136cae86571c104c9f4728ef314da898e02067
parent9986c89c2122f178148d690be336217f754d5633 (diff)
Implement main executable and CLI
-rw-r--r--Rakefile5
-rw-r--r--bin/family_tree.rb5
-rw-r--r--data/actions.txt3
-rw-r--r--lib/cli.rb29
4 files changed, 42 insertions, 0 deletions
diff --git a/Rakefile b/Rakefile
index fa8633d..51dcb8a 100644
--- a/Rakefile
+++ b/Rakefile
@@ -3,6 +3,11 @@
require 'rake'
require 'rspec/core/rake_task'
+desc 'Run the application'
+task :run do
+ sh 'ruby ./bin/family_tree.rb ./data/actions.txt'
+end
+
RSpec::Core::RakeTask.new(:spec) do |t|
t.pattern = 'spec/**/*_spec.rb'
end
diff --git a/bin/family_tree.rb b/bin/family_tree.rb
new file mode 100644
index 0000000..5acc9bb
--- /dev/null
+++ b/bin/family_tree.rb
@@ -0,0 +1,5 @@
+# frozen_string_literal: true
+
+require_relative '../lib/cli'
+
+CLI.new(ARGV).run
diff --git a/data/actions.txt b/data/actions.txt
new file mode 100644
index 0000000..f7e1ff0
--- /dev/null
+++ b/data/actions.txt
@@ -0,0 +1,3 @@
+ADD_CHILD Flora Minerva Female
+GET_RELATIONSHIP Remus Maternal-Aunt
+GET_RELATIONSHIP Minerva Siblings \ No newline at end of file
diff --git a/lib/cli.rb b/lib/cli.rb
new file mode 100644
index 0000000..f2b185d
--- /dev/null
+++ b/lib/cli.rb
@@ -0,0 +1,29 @@
+# frozen_string_literal: true
+
+class CLI
+ def initialize(args)
+ @args = args
+ validate_arguments
+ end
+
+ def run
+ file_path = @args[0]
+ puts "Running actions from file: #{file_path} against the family tree."
+ 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