Sha256: affdcd7409aca9052dcd3237fe6184cf46f41c7191ed03d75b9e8951c2d17e43

Contents?: true

Size: 1.21 KB

Versions: 3

Compression:

Stored size: 1.21 KB

Contents

require 'open3'

require 'bob_the_helper/environment'
require 'bob_the_helper/command/command_result'

module BobTheHelper
  module Command
    include Environment

    # Execute command
    #
    # @param [String] cmd
    #   the command 
    #
    # @param [Hash] options
    #   the options for command execution
    #
    # @option options [Hash] env ({])
    #   the environment variables for the command ('VAR' => 'CONTENT')
    #
    # @option options [String] stdin (nil)
    #   the string for stdin of the command
    #
    # @option options [TrueClass,FalseClass] binmode (false)
    #   should the stdin be read a binary or not
    #
    # @return [CommandResult]
    #   the result of the command execution
    #
    # @return [CommandResult]
    #   the result of the command execution
    def run_command(cmd,options={})
      opts = {
        env: nil,
        stdin: nil,
        binmode: false,
      }.merge options

      env = opts[:env] || ENV.to_hash
      stdin = opts[:stdin] 
      binmode = opts[:binmode]

      result = CommandResult.new
      result.stdout, result.stderr, result.status = Open3.capture3(env, cmd, stdin_data: stdin, chdir: working_directory, binmode: binmode)

      result
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
pointrb-0.1.2 lib/bob_the_helper/command.rb
pointrb-0.1.1 lib/bob_the_helper/command.rb
pointrb-0.1.0 lib/bob_the_helper/command.rb