From 4570ee37e6260eac001fcae2e0ef8fc8d9fce260 Mon Sep 17 00:00:00 2001 From: Bill Niblock Date: Sun, 7 May 2017 16:51:00 -0400 Subject: [PATCH] sapling.rb: Multiple fixes - Add logic for Planter, the editor module - Add logic for catching a bad switch, and reporting accordingly - Add logic for when no tree is included when required, and reporting accordingly - Move YAML file loading from Dialogue/Gardner to here --- lib/sapling.rb | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/lib/sapling.rb b/lib/sapling.rb index 7bfba7b..890f562 100644 --- a/lib/sapling.rb +++ b/lib/sapling.rb @@ -6,6 +6,7 @@ require 'yaml' require_relative 'sapling/dialogue' require_relative 'sapling/gardner' require_relative 'sapling/planter' +require_relative 'sapling/utility' # Sapling is the main module for the program. From here, the rest of the world # starts building. @@ -31,29 +32,50 @@ module Sapling "Begin traversing the provided dialogue tree") do if ARGV.empty? + puts "No tree file provided. Please provide a tree file." puts opt_parser exit end - unless Gardner.verify_tree(ARGV[0]) + unless verify_tree(ARGV[0]) puts "\n#{opt}\n" exit end + puts "Welcome to Sapling, a Dialogue Tree Utility.\n" speaker = Dialogue::Speaker.new - speaker.file = ARGV + speaker.file = YAML.load_file(ARGV[0]) speaker.conversation end opt.on("-e", "--edit", "Create or edit a dialogue tree") do - puts "We gonna make a tree!" + + if ARGV.empty? + puts "Creating a new tree." + tree = SKELETON_TREE + else + puts "Using tree at #{ARGV[0]}." + unless verify_tree(ARGV[0]) + puts "\n#{opt}\n" + exit + end + tree = YAML.load_file(ARGV[0]) + end + + puts "Welcome to Sapling, a Dialogue Tree Utility.\n" + gardner = Planter::Spade.new + gardner.file = tree + gardner.plant end end - opt_parser.parse!(options) - if ARGV.empty? + # Hacky way of dealing with bad options + begin + opt_parser.parse!(options) + rescue OptionParser::InvalidOption + puts "Invalid option." puts opt_parser exit end