Sha256: 1c0f1bfc66f88c1384de345bde678be0299448c2407c4127725ea34a73105b6c

Contents?: true

Size: 1.66 KB

Versions: 12

Compression:

Stored size: 1.66 KB

Contents

class Tryouts; class Drill; module Sergeant
  
  # = CLI
  # 
  # The sergeant responsible for running command-line interface drills.
  #
  class CLI
  
    attr_reader :rbox
    
      # An Array of arguments to be sent to +rbox.send(*rbox_args)+
    attr_accessor :rbox_args
    
    def initialize(*args)
      require 'rye'
      @rbox_args = args
      @rbox = Rye::Box.new
    end
  
    # NOTE: Context is ignored for the CLI Sergeant. 
    def run(block, context=nil, &inline)
      # A Proc object takes precedence over an inline block. 
      runtime = (block.nil? ? inline : block)
      response = Tryouts::Drill::Reality.new
      begin
        if runtime.nil?
          ret = @rbox.send *@rbox_args
        else
          ret = @rbox.instance_eval &runtime
        end
        response.ecode = ret.exit_code
        if ret.stdout.size == 1
          response.output = ret.stdout.first 
        else
          response.output = Array.new(ret.stdout)  # Cast the Rye::Rap object
        end
        response.error = ret.stderr unless ret.stderr.empty?
      rescue Rye::CommandNotFound => ex
        puts ex.message, ex.backtrace if Tryouts.verbose > 2
        response.etype = ex.class
        response.ecode = ex.exit_code
        response.error = "[#{@rbox.host}] Command not found: #{ex.message}"
        response.trace = ex.backtrace
      rescue Rye::CommandError => ex
        puts ex.message, ex.backtrace if Tryouts.verbose > 2
        response.etype = ex.class
        response.ecode = ex.exit_code
        response.output = ex.stdout
        response.error = ex.stderr.join $/
        response.trace = ex.backtrace
      end
      response
    end
    
  end
  
end; end; end

Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
delano-tryouts-0.6.3 lib/tryouts/drill/sergeant/cli.rb
delano-tryouts-0.7.0 lib/tryouts/drill/sergeant/cli.rb
delano-tryouts-0.7.1 lib/tryouts/drill/sergeant/cli.rb
delano-tryouts-0.7.2 lib/tryouts/drill/sergeant/cli.rb
delano-tryouts-0.7.3 lib/tryouts/drill/sergeant/cli.rb
delano-tryouts-0.7.4 lib/tryouts/drill/sergeant/cli.rb
tryouts-0.6.3 lib/tryouts/drill/sergeant/cli.rb
tryouts-0.7.0 lib/tryouts/drill/sergeant/cli.rb
tryouts-0.7.1 lib/tryouts/drill/sergeant/cli.rb
tryouts-0.7.2 lib/tryouts/drill/sergeant/cli.rb
tryouts-0.7.3 lib/tryouts/drill/sergeant/cli.rb
tryouts-0.7.4 lib/tryouts/drill/sergeant/cli.rb