Module: Chef::Mixin::ShellOut

Constant Summary collapse

DEPRECATED_OPTIONS =
[ [:command_log_level,   :log_level],
[:command_log_prepend, :log_tag] ]

Instance Method Summary collapse

Instance Method Details

#run_command_compatible_options(command_args) ⇒ Object

CHEF-3090: Deprecate command_log_level and command_log_prepend Patterned after github.com/opscode/chef/commit/e1509990b559984b43e428d4d801c394e970f432



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/chef/mixin/shell_out.rb', line 65

def run_command_compatible_options(command_args)
  return command_args unless command_args.last.is_a?(Hash)

  my_command_args = command_args.dup
  my_options = my_command_args.last

  DEPRECATED_OPTIONS.each do |old_option, new_option|
    # Edge case: someone specifies :command_log_level and 'command_log_level' in the option hash
    next unless value = my_options.delete(old_option) || my_options.delete(old_option.to_s)
    deprecate_option old_option, new_option
    my_options[new_option] = value
  end

  return my_command_args
end

#shell_out(*args, **options) ⇒ Object

we use ‘en_US.UTF-8’ by default because we parse localized strings in English as an API and generally must support UTF-8 unicode.



31
32
33
34
35
36
37
38
39
40
# File 'lib/chef/mixin/shell_out.rb', line 31

def shell_out(*args, **options)
  options = options.dup
  env_key = options.has_key?(:env) ? :env : :environment
  options[env_key] = {
    "LC_ALL" => Chef::Config[:internal_locale],
    "LANGUAGE" => Chef::Config[:internal_locale],
    "LANG" => Chef::Config[:internal_locale],
  }.update(options[env_key] || {})
  shell_out_command(*args, **options)
end

#shell_out!(*command_args) ⇒ Object

call shell_out (using en_US.UTF-8) and raise errors



43
44
45
46
47
# File 'lib/chef/mixin/shell_out.rb', line 43

def shell_out!(*command_args)
  cmd = shell_out(*command_args)
  cmd.error!
  cmd
end

#shell_out_with_systems_locale(*command_args) ⇒ Object



49
50
51
# File 'lib/chef/mixin/shell_out.rb', line 49

def shell_out_with_systems_locale(*command_args)
  shell_out_command(*command_args)
end

#shell_out_with_systems_locale!(*command_args) ⇒ Object



53
54
55
56
57
# File 'lib/chef/mixin/shell_out.rb', line 53

def shell_out_with_systems_locale!(*command_args)
  cmd = shell_out_with_systems_locale(*command_args)
  cmd.error!
  cmd
end