From 16f19ebef900faebb30e3241e7be83cc925ddf6e Mon Sep 17 00:00:00 2001 From: William Starling Date: Fri, 25 Mar 2022 15:59:06 +0000 Subject: [PATCH] Make call to shell_out compatible with Ruby 3 In previous versions of Ruby, calling `shell_out("cmd", { blah : "blah" })` would be interpreted correctly [here](https://github.com/chef/mixlib-shellout/blob/e2ec87f6f5933e5e5bc75a9fe08a8c8c73e55b72/lib/mixlib/shellout/helper.rb#L38) as `args = "cmd"` and `options = { blah : "blah" }`. However because this can be ambiguous to interpret, Ruby would give the warning: ``` warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call ``` As of Ruby 3, `shell_out("cmd", { blah : "blah" })` will be interpreted as `args = ["cmd", { blah : "blah" }]` and `options = {}`. This can be fixed by passing in the `options` parameter with a double splat (**) in front of it to explicitly convert the hash into a keyword argument. Signed-off-by: William Starling --- libraries/helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/helpers.rb b/libraries/helpers.rb index 021d818..c4fa3ad 100644 --- a/libraries/helpers.rb +++ b/libraries/helpers.rb @@ -121,7 +121,7 @@ def binary_exists? def safe_sv_shellout(command, options = {}) begin Chef::Log.debug("Attempting to run runit command: #{new_resource.sv_bin} #{command}") - cmd = shell_out("#{new_resource.sv_bin} #{command}", options) + cmd = shell_out("#{new_resource.sv_bin} #{command}", **options) rescue Errno::ENOENT if binary_exists? raise # Some other cause