module Mixlib::ShellOut::Helper

def __apply_default_env(options)

Other tags:
    Api: - private
def __apply_default_env(options)
  options = options.dup
  default_env = options.delete(:default_env)
  default_env = true if default_env.nil?
  if default_env
    env_key = options.key?(:env) ? :env : :environment
    options[env_key] = {
      "LC_ALL" => __config[:internal_locale],
      "LANGUAGE" => __config[:internal_locale],
      "LANG" => __config[:internal_locale],
      __env_path_name => default_paths,
    }.update(options[env_key] || {})
  end
  options
end

def __clean_array(*args)

Returns:
  • (Array) - array of strings with nil and null string rejection

Parameters:
  • args (String) -- variable number of string arguments
def __clean_array(*args)
  args.flatten.compact.map(&:to_s)
end

def __env_path_name

def __env_path_name
  if ChefUtils.windows?
    "Path"
  else
    "PATH"
  end
end

def __io_for_live_stream

def __io_for_live_stream
  if !STDOUT.closed? && __log.trace?
    STDOUT
  else
    nil
  end
end

def __maybe_add_timeout(obj, options)

Other tags:
    Api: - private
def __maybe_add_timeout(obj, options)
  options = options.dup
  # historically resources have not properly declared defaults on their timeouts, so a default default of 900s was enforced here
  default_val = 900
  return options if options.key?(:timeout)
  # FIXME: need to nuke descendent tracker out of Chef::Provider so we can just define that class here without requiring the
  # world, and then just use symbol lookup
  if obj.class.ancestors.map(&:name).include?("Chef::Provider") && obj.respond_to?(:new_resource) && obj.new_resource.respond_to?(:timeout) && !options.key?(:timeout)
    options[:timeout] = obj.new_resource.timeout ? obj.new_resource.timeout.to_f : default_val
  end
  options
end

def __shell_out_command(*args, **options)

def __shell_out_command(*args, **options)
  if __transport_connection
    FakeShellOut.new(args, options, __transport_connection.run_command(args.join(" "))) # FIXME: train should accept run_command(*args)
  else
    cmd = if options.empty?
            Mixlib::ShellOut.new(*args)
          else
            Mixlib::ShellOut.new(*args, **options)
          end
    cmd.live_stream ||= __io_for_live_stream
    cmd.run_command
    cmd
  end
end

def shell_out(*args, **options)

def shell_out(*args, **options)
  options = options.dup
  options = __maybe_add_timeout(self, options)
  if options.empty?
    shell_out_compacted(*__clean_array(*args))
  else
    shell_out_compacted(*__clean_array(*args), **options)
  end
end

def shell_out!(*args, **options)

def shell_out!(*args, **options)
  options = options.dup
  options = __maybe_add_timeout(self, options)
  if options.empty?
    shell_out_compacted!(*__clean_array(*args))
  else
    shell_out_compacted!(*__clean_array(*args), **options)
  end
end

def shell_out_compacted(*args, **options)


that the default_env implementation can change without breaking unit tests.
:shell_out_compacted for `default_env: false`, rather than the expanded env settings so
Note that when setting `default_env: false` that you should just setup an expectation on

provider.shell_out!(["foo", nil, "bar" ], ["baz"])
provider.shell_out!("foo", [ "bar", nil, "baz"])

Is met by many different possible calling conventions that mean the same thing:

allow(provider).to receive(:shell_out_compacted!).with("foo", "bar", "baz")

This expectation:

for less brittle rspec tests.
in rspec tests. They should always be used in rspec tests instead of shell_out to allow
The shell_out_compacted/shell_out_compacted! APIs are private but are intended for use
def shell_out_compacted(*args, **options)
  options = __apply_default_env(options)
  if options.empty?
    __shell_out_command(*args)
  else
    __shell_out_command(*args, **options)
  end
end

def shell_out_compacted!(*args, **options)

def shell_out_compacted!(*args, **options)
  options = __apply_default_env(options)
  cmd = if options.empty?
          __shell_out_command(*args)
        else
          __shell_out_command(*args, **options)
        end
  cmd.error!
  cmd
end