diff options
author | Ho-Sheng Hsiao <hosheng.hsiao@gmail.com> | 2012-03-30 21:30:05 -0400 |
---|---|---|
committer | Ho-Sheng Hsiao <hosh@opscode.com> | 2012-05-10 14:51:40 -0400 |
commit | 0a918626c0c4329da079e72e93e4c3a22baee683 (patch) | |
tree | 6cbebdb002263e64b821e1370d6c47fb7a57d4f6 /lib | |
parent | cf71f71368646904f39ef6012424b41488a38c58 (diff) | |
download | mixlib-shellout-0a918626c0c4329da079e72e93e4c3a22baee683.tar.gz |
[CHEF-2994][WINDOWS] Broke up #command_to_run into manageable chunks
May reuse some of these as class methods so they are available as convention/utilities accessible to anyone on the Windows platform
Diffstat (limited to 'lib')
-rw-r--r-- | lib/mixlib/shellout/windows.rb | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/lib/mixlib/shellout/windows.rb b/lib/mixlib/shellout/windows.rb index fa4990b..0e55e0b 100644 --- a/lib/mixlib/shellout/windows.rb +++ b/lib/mixlib/shellout/windows.rb @@ -156,25 +156,15 @@ module Mixlib IS_BATCH_FILE = /\.bat"?$|\.cmd"?$/i - def command_to_run - if command =~ /^\s*"(.*)"/ - # If we have quotes, do an exact match - candidate = $1 - else - # Otherwise check everything up to the first space - candidate = command[0,command.index(/\s/) || command.length].strip - end + def command_to_run(command) + candidate = candidate_executable_for_command(command) # Don't do searching for empty commands. Let it fail when it runs. - if candidate.length == 0 - return [ nil, command ] - end + return [ nil, command ] if candidate.length == 0 # Check if the exe exists directly. Otherwise, search PATH. exe = find_exe_at_location(candidate) - if exe.nil? && exe !~ /[\\\/]/ - exe = which(command[0,command.index(/\s/) || command.length]) - end + exe = which(unquoted_executable_path(command)) if exe.nil? && exe !~ /[\\\/]/ if exe.nil? || exe =~ IS_BATCH_FILE # Batch files MUST use cmd; and if we couldn't find the command we're looking for, we assume it must be a cmd builtin. @@ -188,6 +178,21 @@ module Mixlib end end + def unquoted_executable_path(command) + command[0,command.index(/\s/) || command.length] + end + + def candidate_executable_for_command(command) + if command =~ /^\s*"(.*?)"/ + # If we have quotes, do an exact match + $1 + else + # Otherwise check everything up to the first space + unquoted_executable_path(command).strip + end + end + + def inherit_environment result = {} ENV.each_pair do |k,v| |