Modifies to use util/which [GH-654]

This commit is contained in:
Gabor Nagy 2013-06-02 03:48:47 +02:00
parent 0936267314
commit 4c00abe69e
2 changed files with 13 additions and 4 deletions

View File

@ -163,6 +163,14 @@ module Vagrant
error_key(:cli_invalid_options) error_key(:cli_invalid_options)
end end
class CommandUnavailable < VagrantError
error_key(:command_unavailable)
end
class CommandUnavailableWindows < VagrantError
error_key(:command_unavailable_windows)
end
class ConfigInvalid < VagrantError class ConfigInvalid < VagrantError
error_key(:config_invalid) error_key(:config_invalid)
end end

View File

@ -5,6 +5,7 @@ require 'log4r'
require 'vagrant/util/platform' require 'vagrant/util/platform'
require 'vagrant/util/safe_chdir' require 'vagrant/util/safe_chdir'
require 'vagrant/util/which'
module Vagrant module Vagrant
module Util module Util
@ -26,10 +27,10 @@ module Vagrant
def initialize(*command) def initialize(*command)
@options = command.last.is_a?(Hash) ? command.pop : {} @options = command.last.is_a?(Hash) ? command.pop : {}
@command = command @command = command
if Platform.windows? @command[0] = Which.which(@command[0])
locations = `where #{command[0]}` unless @command[0]
new_command = "#{locations.split("\n")[0]}" raise Errors::CommandUnavailableWindows if Platform.windows?
@command[0] = new_command if $?.success? and File.exists?(new_command) raise Errors::CommandUnavailable
end end
@logger = Log4r::Logger.new("vagrant::util::subprocess") @logger = Log4r::Logger.new("vagrant::util::subprocess")
end end