From 1d1b3511e4c523458d78653cb8781a5328600387 Mon Sep 17 00:00:00 2001 From: Szymon Szukalski Date: Thu, 24 Oct 2024 11:32:34 +1100 Subject: Implement main executable and CLI --- Rakefile | 5 +++++ bin/family_tree.rb | 5 +++++ data/actions.txt | 3 +++ lib/cli.rb | 29 +++++++++++++++++++++++++++++ 4 files changed, 42 insertions(+) create mode 100644 bin/family_tree.rb create mode 100644 data/actions.txt create mode 100644 lib/cli.rb 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 ' + 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 -- cgit v1.2.3