lib/ego/runner.rb in ego-0.5.0 vs lib/ego/runner.rb in ego-0.6.0

- old
+ new

@@ -1,16 +1,19 @@ +# frozen_string_literal: true + require_relative '../ego' require_relative 'options' +require_relative 'plugin_helper' module Ego # The Runner class, given an array of arguments, initializes the required # objects and executes the request. class Runner # Prompt to display in shell-mode PROMPT = 'ego, '.green.freeze # Pattern that triggers shell-mode to exit - QUIT = /^q(uit)?|exit|(good)?bye$/.freeze + QUIT = /^q(uit)?|exit|(good)?bye$/ # Takes an array of arguments and parses them into options: # # @example # runner = Ego::Runner.new(ARGV) @@ -25,19 +28,23 @@ # # @return [void] def run case @options.mode when :help - if @options.usage_error - Printer.errs @options.usage_error, "\n" - end + Printer.errs @options.usage_error, "\n" if @options.usage_error Printer.puts @options.usage exit(-1) if @options.usage_error when :version Printer.puts "ego v#{Ego::VERSION}" + when :template + helper = PluginHelper.new( + query: (@options.query unless @options.query.empty?), + program_name: @options.usage.program_name + ) + Printer.puts helper.template when :shell start_shell(robot_factory) else handle_query(robot_factory, @options.query) end @@ -52,12 +59,10 @@ # # @return [Robot] a decorated robot instance def robot_factory Plugin.load Filesystem.builtin_plugins - if @options.plugins - Plugin.load Filesystem.user_plugins - end + Plugin.load Filesystem.user_plugins if @options.plugins Plugin.decorate(Robot.new(@options)).ready end # Handle and single query and shut down.