Sha256: ff457a7800abaa0fed987183bdf8b3aa591ce466f0afb6411753dc69dd58e019

Contents?: true

Size: 707 Bytes

Versions: 1

Compression:

Stored size: 707 Bytes

Contents

module DMTool::CLI
  class << self
    def start
      @parser = DMTool::Parser.new
      ui_loop
      true
    end

    private

    def input
      @input ||= $stdin
    end

    def output
      @output ||= $stdout
    end

    def ui_loop
      prompt do
        while str = input.gets.chomp rescue ''
          break if str.blank?
          begin
            output.puts @parser.parse(str)
          rescue SystemExit => e
            output.puts 'Goodbye'
            break
          rescue => e
            output.puts "#{e.class} #{e.message}"
          end
          prompt
        end
      end
    end

    def prompt
      output.print 'dmtool > '
      yield if block_given?
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dmtool-0.0.1 lib/dmtool/cli.rb