summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2020-05-21 19:45:51 -0700
committerGitHub <noreply@github.com>2020-05-21 19:45:51 -0700
commit847e3fb6ed2f9947c5f993234cd71a84227fdb9c (patch)
tree69716cb28f0265cbdea1c00bb914c8d1c7200e74
parent0ab281b84826ef6f8ff5c2c9586381a76be47a59 (diff)
parentf139ed9def94473710eb7d00685576c6df627b58 (diff)
downloadchef-847e3fb6ed2f9947c5f993234cd71a84227fdb9c.tar.gz
Merge pull request #9897 from chef/fix-ruby27-keyword-arg-warning-in-macos_userdefaults
macos_userdefaults: Fix ruby 2.7 keyword args warning and refactor a bit
-rw-r--r--cspell.json1
-rw-r--r--lib/chef/resource/macos_userdefaults.rb17
2 files changed, 11 insertions, 7 deletions
diff --git a/cspell.json b/cspell.json
index 6d661c83b8..e70f7cf460 100644
--- a/cspell.json
+++ b/cspell.json
@@ -1119,7 +1119,6 @@
"dracut",
"dragonflybsd",
"dragonsmith",
- "drcmd",
"drzewiec",
"dscacheutil",
"dscl",
diff --git a/lib/chef/resource/macos_userdefaults.rb b/lib/chef/resource/macos_userdefaults.rb
index a8158aba5e..bc3bab67fd 100644
--- a/lib/chef/resource/macos_userdefaults.rb
+++ b/lib/chef/resource/macos_userdefaults.rb
@@ -74,12 +74,17 @@ class Chef
load_current_value do |desired|
value = coerce_booleans(desired.value)
- drcmd = "defaults read '#{desired.domain}' "
- drcmd << "'#{desired.key}' " if desired.key
- shell_out_opts = {}
- shell_out_opts[:user] = desired.user unless desired.user.nil?
- vc = shell_out("#{drcmd} | grep -qx '#{value}'", shell_out_opts)
- is_set vc.exitstatus == 0 ? true : false
+ cmd = "defaults read '#{desired.domain}' "
+ cmd << "'#{desired.key}' " if desired.key
+ cmd << " | grep -qx '#{value}'"
+
+ vc = if desired.user.nil?
+ shell_out(cmd)
+ else
+ shell_out(cmd, user: desired.user)
+ end
+
+ is_set !vc.error?
end
action :write do