Sha256: f403f4b67a48c910b664e834617626850ab6f8ae143b9b13be61138c8b62408f

Contents?: true

Size: 1.01 KB

Versions: 1

Compression:

Stored size: 1.01 KB

Contents

require 'readline'

module MM
  module Command
    class Console
      def run
        @runtime = MM::RuntimeRepository.load
        @runtime[:api] = MM::API.new(@runtime)
        at_exit {
          @runtime.delete(:api)
          MM::RuntimeRepository.save(@runtime)
          puts 'Bye'
        }
        loop do
          do_once
        end
      end

      def do_once
        prompt = "#{project}> #{@runtime[:context]}> "
        input = Readline.readline(prompt, true).strip
        return if input.blank?
        exit(0) if input =~ /^(exit|quit)$/i
        begin
          ret = MM::Console::Processor.new(@runtime).process(input)
          puts ret unless ret.blank?
        rescue
          puts "mm: #{$!.message}"
          if @runtime[:debug].to_s == 'true'
            puts ''
            puts '---------- debug -----------'
            puts $!.backtrace.join("\n") 
            puts ''
          end
        end
      end
      
      def project
        @runtime[:site].to_s.split('/').last
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
xli-mm-0.0.3 lib/mm/command/console.rb