Sha256: 59f72229e110cfb2ee28c1332938e41c4cf87137218da02f63fefc28829f28e4

Contents?: true

Size: 862 Bytes

Versions: 19

Compression:

Stored size: 862 Bytes

Contents

require 'mattock/command-line'

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

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

      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

19 entries across 19 versions & 1 rubygems

Version Path
mattock-0.3.0 lib/mattock/testing/record-commands.rb
mattock-0.2.13 lib/mattock/testing/record-commands.rb
mattock-0.2.12 lib/mattock/testing/record-commands.rb
mattock-0.2.11 lib/mattock/testing/record-commands.rb
mattock-0.2.10 lib/mattock/testing/record-commands.rb
mattock-0.2.9 lib/mattock/testing/record-commands.rb
mattock-0.2.8 lib/mattock/testing/record-commands.rb
mattock-0.2.7 lib/mattock/testing/record-commands.rb
mattock-0.2.6 lib/mattock/testing/record-commands.rb
mattock-0.2.5 lib/mattock/testing/record-commands.rb
mattock-0.2.4 lib/mattock/testing/record-commands.rb
mattock-0.2.3 lib/mattock/testing/record-commands.rb
mattock-0.2.2 lib/mattock/testing/record-commands.rb
mattock-0.2.1 lib/mattock/testing/record-commands.rb
mattock-0.2.0 lib/mattock/testing/record-commands.rb
mattock-0.1.3 lib/mattock/testing/record-commands.rb
mattock-0.1.2 lib/mattock/testing/record-commands.rb
mattock-0.1.1 lib/mattock/testing/record-commands.rb
mattock-0.1.0 lib/mattock/testing/record-commands.rb