Sha256: 903883391d3767251af88e8b7601aec3d416e7828d961c95890193d14731a189

Contents?: true

Size: 857 Bytes

Versions: 83

Compression:

Stored size: 857 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

83 entries across 83 versions & 2 rubygems

Version Path
inspec-core-2.3.28 lib/utils/command_wrapper.rb
inspec-2.3.28 lib/utils/command_wrapper.rb
inspec-core-3.0.9 lib/utils/command_wrapper.rb
inspec-3.0.9 lib/utils/command_wrapper.rb
inspec-core-3.0.0 lib/utils/command_wrapper.rb
inspec-3.0.0 lib/utils/command_wrapper.rb
inspec-core-2.3.24 lib/utils/command_wrapper.rb
inspec-2.3.24 lib/utils/command_wrapper.rb
inspec-core-2.3.23 lib/utils/command_wrapper.rb
inspec-2.3.23 lib/utils/command_wrapper.rb
inspec-core-2.3.10 lib/utils/command_wrapper.rb
inspec-2.3.10 lib/utils/command_wrapper.rb
inspec-core-2.3.5 lib/utils/command_wrapper.rb
inspec-2.3.5 lib/utils/command_wrapper.rb
inspec-core-2.3.4 lib/utils/command_wrapper.rb
inspec-2.3.4 lib/utils/command_wrapper.rb
inspec-core-2.2.112 lib/utils/command_wrapper.rb
inspec-2.2.112 lib/utils/command_wrapper.rb
inspec-core-2.2.102 lib/utils/command_wrapper.rb
inspec-2.2.102 lib/utils/command_wrapper.rb