Module: Poise::Utils::ShellOut
Overview
A mixin to provider a better shell_out.
Class Method Summary collapse
-
.poise_shell_out(*command_args, **options) ⇒ Mixlib::ShellOut
An enhanced version of Chef's
shell_out
which sets some default parameters. -
.poise_shell_out!(*command_args) ⇒ Mixlib::ShellOut
The
error!
version of #poise_shell_out.
Instance Method Summary collapse
-
#poise_shell_out(*command_args, **options) ⇒ Mixlib::ShellOut
An enhanced version of Chef's
shell_out
which sets some default parameters. -
#poise_shell_out!(*command_args) ⇒ Mixlib::ShellOut
The
error!
version of #poise_shell_out.
Class Method Details
.poise_shell_out(*command_args, **options) ⇒ Mixlib::ShellOut
An enhanced version of Chef's shell_out
which sets some default
parameters. If possible it will set $HOME, $USER, $LOGNAME, and the
group to run as.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/poise/utils/shell_out.rb', line 41 def poise_shell_out(*command_args, **) # Allow the env option shorthand. [:environment] ||= {} if [:env] [:environment].update([:env]) .delete(:env) end # Convert environment keys to strings to be safe. [:environment] = [:environment].inject({}) do |memo, (key, value)| memo[key.to_s] = value.to_s memo end # Populate some standard environment variables. ent = begin if [:user].is_a?(Integer) Etc.getpwuid([:user]) elsif [:user] Etc.getpwnam([:user]) end rescue ArgumentError nil end username = ent ? ent.name : [:name] if username [:environment]['HOME'] ||= Dir.home(username) [:environment]['USER'] ||= username # On the off chance they set one manually but not the other. [:environment]['LOGNAME'] ||= [:environment]['USER'] end # Set the default group on Unix. [:group] ||= ent.gid if ent # Mixlib-ShellOut doesn't support array commands on Windows and has # super wonky escaping for cmd.exe. if respond_to?(:node) && node.platform_family?('windows') command_args = [Poise::Utils::Win32.reparse_command(*command_args)] end # Call Chef's shell_out wrapper. shell_out(*command_args, **) end |
.poise_shell_out!(*command_args) ⇒ Mixlib::ShellOut
The error!
version of #poise_shell_out.
85 86 87 |
# File 'lib/poise/utils/shell_out.rb', line 85 def poise_shell_out!(*command_args) poise_shell_out(*command_args).tap(&:error!) end |
Instance Method Details
#poise_shell_out(*command_args, **options) ⇒ Mixlib::ShellOut
An enhanced version of Chef's shell_out
which sets some default
parameters. If possible it will set $HOME, $USER, $LOGNAME, and the
group to run as.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/poise/utils/shell_out.rb', line 41 def poise_shell_out(*command_args, **) # Allow the env option shorthand. [:environment] ||= {} if [:env] [:environment].update([:env]) .delete(:env) end # Convert environment keys to strings to be safe. [:environment] = [:environment].inject({}) do |memo, (key, value)| memo[key.to_s] = value.to_s memo end # Populate some standard environment variables. ent = begin if [:user].is_a?(Integer) Etc.getpwuid([:user]) elsif [:user] Etc.getpwnam([:user]) end rescue ArgumentError nil end username = ent ? ent.name : [:name] if username [:environment]['HOME'] ||= Dir.home(username) [:environment]['USER'] ||= username # On the off chance they set one manually but not the other. [:environment]['LOGNAME'] ||= [:environment]['USER'] end # Set the default group on Unix. [:group] ||= ent.gid if ent # Mixlib-ShellOut doesn't support array commands on Windows and has # super wonky escaping for cmd.exe. if respond_to?(:node) && node.platform_family?('windows') command_args = [Poise::Utils::Win32.reparse_command(*command_args)] end # Call Chef's shell_out wrapper. shell_out(*command_args, **) end |
#poise_shell_out!(*command_args) ⇒ Mixlib::ShellOut
The error!
version of #poise_shell_out.
85 86 87 |
# File 'lib/poise/utils/shell_out.rb', line 85 def poise_shell_out!(*command_args) poise_shell_out(*command_args).tap(&:error!) end |