module PoiseLanguages::Command::Mixin::Provider
A mixin for providers that run language commands.
Private Instance Methods
language_command_shell_out(name, *command_args, **options)
click to toggle source
Run a command using the configured language via `shell_out`.
@api private @param name [Symbol] Language name. @param command_args [Array] Arguments to `shell_out`. @return [Mixlib::ShellOut]
# File lib/poise_languages/command/mixin.rb, line 174 def language_command_shell_out(name, *command_args, **options) # Inject our environment variables if needed. options[:environment] ||= {} parent = new_resource.send(:"parent_#{name}") if parent options[:environment].update(parent.send(:"#{name}_environment")) end # Inject other options. options[:timeout] ||= new_resource.timeout # Find the actual binary to use. Raise an exception if we see false # which happens if no parent resource is found, no explicit default # binary was given, and which() fails to find a thing. binary = new_resource.send(name) raise Error.new("Unable to find a #{name} binary for command: #{command_args.is_a?(Array) ? Shellwords.shelljoin(command_args) : command_args}") unless binary command = if command_args.length == 1 && command_args.first.is_a?(String) # String mode, sigh. "#{Shellwords.escape(binary)} #{command_args.first}" else # Array mode. Handle both ('one', 'two') and (['one', 'two']). [binary] + command_args.flatten end Chef::Log.debug("[#{new_resource}] Running #{name} command: #{command.is_a?(Array) ? Shellwords.shelljoin(command) : command}") # Run the command poise_shell_out(command, options) end
language_command_shell_out!(name, *command_args)
click to toggle source
Run a command using the configured language via `shell_out!`.
@api private @param name [Symbol] Language name. @param command_args [Array] Arguments to `shell_out!`. @return [Mixlib::ShellOut]
# File lib/poise_languages/command/mixin.rb, line 206 def language_command_shell_out!(name, *command_args) send(:"#{name}_shell_out", *command_args).tap(&:error!) end