mirror of
https://github.com/inspec/inspec
synced 2024-11-24 05:33:17 +00:00
4b9acb4800
* Bump Rubocop to 0.49.1 This change bumps Rubocop to 0.49.1. There have been a lot of changes since 0.39.0 and this PR is hopefully a nice compromise of turning off certain cops and updating our codebase to take advantage of new Ruby 2.3 methods and operators. Signed-off-by: Adam Leff <adam@leff.co> * Set end-of-line format to line-feed only, avoid Windows-related CRLF issues Signed-off-by: Adam Leff <adam@leff.co>
27 lines
857 B
Ruby
27 lines
857 B
Ruby
# 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
|