lib/appscrolls/command.rb in appscrolls-0.8.4 vs lib/appscrolls/command.rb in appscrolls-0.9.0

- old
+ new

@@ -11,23 +11,27 @@ if options[:scrolls] run_template(name, options[:scrolls], options[:template]) else @scrolls = [] - while scroll = ask("#{print_scrolls}#{bold}Which scroll would you like to add? #{clear}#{yellow}(blank to finish)#{clear}") - if scroll == '' - run_template(name, @scrolls) - break + question = "#{bold}Which scroll would you like to add/remove? #{clear}#{yellow}(blank to finish)#{clear}" + while (scroll = ask(scrolls_message + question)) != '' + if @scrolls.include?(scroll) + @scrolls.delete(scroll) + puts + puts "> #{yellow}Removed '#{scroll}' from template.#{clear}" elsif AppScrollsScrolls::Scrolls.list.include?(scroll) @scrolls << scroll puts puts "> #{green}Added '#{scroll}' to template.#{clear}" else puts puts "> #{red}Invalid scroll, please try again.#{clear}" end end + + run_template(name, @scrolls) end end desc "list [CATEGORY]", "list available scrolls (optionally by category)" def list(category = nil) @@ -48,27 +52,29 @@ def bold; "\033[1m" end def red; "\033[31m" end def green; "\033[32m" end def yellow; "\033[33m" end - def print_scrolls - puts - puts - puts + def scrolls_message + message = "\n\n\n" if @scrolls && @scrolls.any? - puts "#{green}#{bold}Your Scrolls:#{clear} " + @scrolls.join(", ") - puts + message << "#{green}#{bold}Your Scrolls:#{clear} #{@scrolls.join(", ")}" + message << "\n\n" end - puts "#{bold}#{cyan}Available Scrolls:#{clear} " + AppScrollsScrolls::Scrolls.list.join(', ') - puts + available_scrolls = AppScrollsScrolls::Scrolls.list - @scrolls + if available_scrolls.any? + message << "#{bold}#{cyan}Available Scrolls:#{clear} #{available_scrolls.join(', ')}" + message << "\n\n" + end + message end def run_template(name, scrolls, display_only = false) puts puts puts "#{bold}Generating and Running Template...#{clear}" puts - file = Tempfile.new('template') + file = Tempfile.new('template') template = AppScrollsScrolls::Template.new(scrolls) puts "Using the following scrolls:" template.resolve_scrolls.map do |scroll| color = scrolls.include?(scroll.new.key) ? green : yellow # yellow - automatic dependency