Sha256: d2575ea855af0a5caf2186c4a50e1dfed58b9476b073ed7df2051911af131d39

Contents?: true

Size: 967 Bytes

Versions: 6

Compression:

Stored size: 967 Bytes

Contents

module Ruboty
  class CommandBuilder
    include Mem

    attr_reader :arguments

    def initialize(arguments = ARGV)
      @arguments = arguments
    end

    def build
      command_class.new(options)
    end

    private

    def command_class
      case
      when options[:generate]
        Commands::Generate
      when options[:help]
        Commands::Help
      else
        Commands::Run
      end
    end

    def options
      Slop.parse(arguments) do |options|
        options.on("--dotenv", "Load .env before running.")
        options.on("-g", "--generate", "Generate a new chatterbot with ./ruboty/ directory if specified.")
        options.on("-h", "--help", "Display this help message.")
        if Slop::VERSION >= "4.0.0"
          options.string("-l", "--load", "Load a ruby file before running.")
        else
          options.on("-l", "--load=", "Load a ruby file before running.")
        end
      end
    end
    memoize :options
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
ruboty-1.2.4 lib/ruboty/command_builder.rb
ruboty-1.2.3 lib/ruboty/command_builder.rb
ruboty-1.2.2 lib/ruboty/command_builder.rb
ruboty-1.2.1 lib/ruboty/command_builder.rb
ruboty-1.2.0 lib/ruboty/command_builder.rb
ruboty-1.1.9 lib/ruboty/command_builder.rb