chef
https://github.com/opscode/chef
Ruby
A systems integration framework, built to bring the benefits of configuration management to your entire infrastructure.
Chef::Mixin::ShellOut#shell_out_compact
PREFERRED APIS: shell_out_compact and shell_out_compact! flatten their array arguments and remove nils and pass the resultant array to shell_out. this actually eliminates spaces-in-args bugs because this: shell_out!("command #{arg}") becomes two arguments if arg has spaces and requires quotations: shell_out!("command '#{arg}'") using shell_out_compact! this becomes: shell_out_compact!("command", arg) and spaces in the arg just works and it does not become two arguments (and the shell quoting around the argument must actually be removed). there's also an implicit join between all the array elements, and nested arrays are flattened which means that odd where-do-i-put-the-spaces options handling just works, and instead of this: opts = "" # needs to be empty string for when foo and bar are both missing opts << " -foo" if needs_foo? # needs the leading space on both of these opts << " -bar" if needs_bar? shell_out!("cmd#{opts}") # have to think way too hard about why there's no space here becomes: opts = [] opts << "-foo" if needs_foo? opts << "-bar" if needs_bar? shell_out_compact!("cmd", opts) and opts can be an empty array or nil and it'll work out fine. generally its best to use shell_out_compact! in code and setup expectations on shell_out! in tests
Edit
git clone [email protected]:opscode/chef.git
cd chef
open lib/chef/mixin/shell_out.rb
Contribute
# Make a new branchgit checkout -b -your-name--update-docs-Chef--Mixin--ShellOut-shell_out_compact-for-pr
# Commit to gitgit add lib/chef/mixin/shell_out.rbgit commit -m "better docs for Chef::Mixin::ShellOut#shell_out_compact"
# Open pull requestgem install hub # on a mac you can `brew install hub`
hub fork
git push <your name> -your-name--update-docs-Chef--Mixin--ShellOut-shell_out_compact-for-pr
hub pull-request
# Celebrate!