Sha256: 1d8acad95565723e3b43ef83f878365924b968aa46895761d096a3c356257dee

Contents?: true

Size: 884 Bytes

Versions: 6

Compression:

Stored size: 884 Bytes

Contents

# encoding: utf-8
# author: Dominik Richter
# author: Christoph Hartmann

require 'shellwords'

class CommandWrapper
  UNIX_SHELLS = %w{sh bash zsh}.freeze

  def self.wrap(cmd, options)
    unless options.is_a?(Hash)
      raise 'All options for the command wrapper must be provided as a hash. '\
        "You entered: #{options.inspect}. Please consult the documentation."
    end

    wrap = options[:wrap]
    raise "Called command wrapper with wrap: #{wrap.inspect}. It must be called with a Proc." if !wrap.nil? && !wrap.is_a?(Proc)
    return wrap.call(cmd) unless wrap.nil?

    shell = options[:shell]
    raise "Don't know how to wrap commands for shell: #{shell.inspect}." unless UNIX_SHELLS.include?(shell)

    path = options[:path] || shell
    args = options[:args] || '-c'
    path.to_s + ' ' + args + ' ' + Shellwords.escape(cmd)
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
inspec-2.1.81 lib/utils/command_wrapper.rb
inspec-2.1.21 lib/utils/command_wrapper.rb
inspec-2.1.10 lib/utils/command_wrapper.rb
inspec-2.0.32 lib/utils/command_wrapper.rb
inspec-2.0.17 lib/utils/command_wrapper.rb
inspec-1.51.15 lib/utils/command_wrapper.rb