diff options
| author | Szymon Szukalski <szymon@skas.io> | 2024-10-24 11:32:34 +1100 |
|---|---|---|
| committer | Szymon Szukalski <szymon@skas.io> | 2024-10-24 11:32:34 +1100 |
| commit | 1d1b3511e4c523458d78653cb8781a5328600387 (patch) | |
| tree | f5136cae86571c104c9f4728ef314da898e02067 | |
| parent | 9986c89c2122f178148d690be336217f754d5633 (diff) | |
Implement main executable and CLI
| -rw-r--r-- | Rakefile | 5 | ||||
| -rw-r--r-- | bin/family_tree.rb | 5 | ||||
| -rw-r--r-- | data/actions.txt | 3 | ||||
| -rw-r--r-- | lib/cli.rb | 29 |
4 files changed, 42 insertions, 0 deletions
@@ -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 |
