Sha256: a8db1e1c06ca30f76616d113d15c6e44a186df05483c5c28d427f286f2313e6a

Contents?: true

Size: 1.34 KB

Versions: 7

Compression:

Stored size: 1.34 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)
      @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.rcode = ret.exit_code
        response.output = ret.stdout.size == 1 ? ret.stdout.first : Array.new(ret.stdout)  # Cast the Rye::Rap object
        response.emsg = ret.stderr unless ret.stderr.empty?
      rescue Rye::CommandNotFound => ex
        response.rcode = -2
        response.emsg = "[#{@rbox.host}] Command not found: #{ex.message}"
        response.backtrace = ex.backtrace
      rescue Rye::CommandError => ex
        response.rcode = ex.exit_code
        response.output = ex.stdout
        response.emsg = ex.stderr
      end
      response
    end
    
  end
  
end; end; end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
delano-tryouts-0.4.1 lib/tryouts/drill/sergeant/cli.rb
delano-tryouts-0.5.0 lib/tryouts/drill/sergeant/cli.rb
delano-tryouts-0.5.1 lib/tryouts/drill/sergeant/cli.rb
tryouts-0.5.0 lib/tryouts/drill/sergeant/cli.rb
tryouts-0.4.0 lib/tryouts/drill/sergeant/cli.rb
tryouts-0.4.1 lib/tryouts/drill/sergeant/cli.rb
tryouts-0.5.1 lib/tryouts/drill/sergeant/cli.rb