Sha256: 1925a12e236cdbfb4a284276ce40f2f9fe6a2af6533cda01780c99df5ec41f92

Contents?: true

Size: 1.07 KB

Versions: 8

Compression:

Stored size: 1.07 KB

Contents

require "optparse"

class Ppl::Application::Shell

  attr_writer :router

  def run(input, output)
    outcome = false
    begin
      command = select_command(input)
      prepare_command(command, input)
      outcome = execute_command(command, input, output)
    rescue Ppl::Error::ContactNotFound
      output.error("ppl: Contact '#{$!}' not found")
    rescue OptionParser::InvalidOption, OptionParser::MissingArgument, Ppl::Error::IncorrectUsage
      output.error($!)
      output.error(@optparse.to_s)
    rescue
      output.error("ppl: " + $!.message)
      outcome = false
    end
    return outcome
  end


  private

  def select_command(input)
    @router.route(input.arguments.shift)
  end

  def prepare_command(command, input)
    if !command.nil?
      @optparse = OptionParser.new do |parser|
        command.options(parser, input.options)
      end
      @optparse.parse!(input.arguments)
    end
  end

  def execute_command(command, input, output)
    outcome = false
    if !command.nil?
      outcome = command.execute(input, output)
    end
    return outcome
  end

end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
ppl-1.12.0 lib/ppl/application/shell.rb
ppl-1.11.0 lib/ppl/application/shell.rb
ppl-1.10.0 lib/ppl/application/shell.rb
ppl-1.9.0 lib/ppl/application/shell.rb
ppl-1.8.0 lib/ppl/application/shell.rb
ppl-1.7.0 lib/ppl/application/shell.rb
ppl-1.6.0 lib/ppl/application/shell.rb
ppl-1.5.3 lib/ppl/application/shell.rb