Sha256: eabcd870f81b3b3a4927b1d0055289f2917ecf5631c2a1a061347fbb5cb048a7

Contents?: true

Size: 832 Bytes

Versions: 11

Compression:

Stored size: 832 Bytes

Contents

require 'mattock/command-line'

module Mattock
  class CommandLine
    @@commands = []
    alias original_execute execute

    def execute
      result = original_execute
      @@commands << [command, result]
      return result
    end

    class << self
      attr_accessor :command_recording_path

      def command_recording_path
        @command_recording_path ||= ENV['MATTOCK_CMDREC']
      end

      def emit_recording
        io = $stderr
        if command_recording_path
          io = File.open(command_recording_path, "w")
        else
          io.puts "Set MATTOCK_CMDREC to write to a path"
        end
        @@commands.each do |pair|
          io.puts "[/#{pair[0]}/, #{[pair[1].exit_code, pair[1].streams].inspect}]"
        end
      end
    end
  end
end

at_exit do
  Mattock::CommandLine.emit_recording
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
mattock-0.7.1 lib/mattock/testing/record-commands.rb
mattock-0.7.0 lib/mattock/testing/record-commands.rb
mattock-0.5.3 lib/mattock/testing/record-commands.rb
mattock-0.5.2 lib/mattock/testing/record-commands.rb
mattock-0.5.0 lib/mattock/testing/record-commands.rb
mattock-0.4.1 lib/mattock/testing/record-commands.rb
mattock-0.4.0 lib/mattock/testing/record-commands.rb
mattock-0.3.4 lib/mattock/testing/record-commands.rb
mattock-0.3.3 lib/mattock/testing/record-commands.rb
mattock-0.3.2 lib/mattock/testing/record-commands.rb
mattock-0.3.1 lib/mattock/testing/record-commands.rb