Make guestpath an optional parameter for synced_folders
This commit is contained in:
parent
c3438ff8f6
commit
d528902edc
|
@ -201,14 +201,25 @@ module VagrantPlugins
|
||||||
# folder.
|
# folder.
|
||||||
# @param [Hash] options Additional options.
|
# @param [Hash] options Additional options.
|
||||||
def synced_folder(hostpath, guestpath, options=nil)
|
def synced_folder(hostpath, guestpath, options=nil)
|
||||||
name = (options && options.delete(:name)) || guestpath
|
|
||||||
if Vagrant::Util::Platform.windows?
|
if Vagrant::Util::Platform.windows?
|
||||||
# On Windows, Ruby just uses normal '/' for path seps, so
|
# On Windows, Ruby just uses normal '/' for path seps, so
|
||||||
# just replace normal Windows style seps with Unix ones.
|
# just replace normal Windows style seps with Unix ones.
|
||||||
hostpath = hostpath.to_s.gsub("\\", "/")
|
hostpath = hostpath.to_s.gsub("\\", "/")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if guestpath.is_a?(Hash)
|
||||||
|
options = guestpath
|
||||||
|
guestpath = nil
|
||||||
|
end
|
||||||
|
|
||||||
options ||= {}
|
options ||= {}
|
||||||
|
|
||||||
|
if options.has_key?(:name)
|
||||||
|
synced_folder_name = options.delete(:name)
|
||||||
|
else
|
||||||
|
synced_folder_name = guestpath
|
||||||
|
end
|
||||||
|
|
||||||
options[:guestpath] = guestpath.to_s.gsub(/\/$/, '')
|
options[:guestpath] = guestpath.to_s.gsub(/\/$/, '')
|
||||||
options[:hostpath] = hostpath
|
options[:hostpath] = hostpath
|
||||||
options[:disabled] = false if !options.key?(:disabled)
|
options[:disabled] = false if !options.key?(:disabled)
|
||||||
|
@ -218,7 +229,7 @@ module VagrantPlugins
|
||||||
# Make sure the type is a symbol
|
# Make sure the type is a symbol
|
||||||
options[:type] = options[:type].to_sym if options[:type]
|
options[:type] = options[:type].to_sym if options[:type]
|
||||||
|
|
||||||
@__synced_folders[name] = options
|
@__synced_folders[synced_folder_name] = options
|
||||||
end
|
end
|
||||||
|
|
||||||
# Define a way to access the machine via a network. This exposes a
|
# Define a way to access the machine via a network. This exposes a
|
||||||
|
|
|
@ -534,6 +534,21 @@ describe VagrantPlugins::Kernel_V2::VMConfig do
|
||||||
subject.finalize!
|
subject.finalize!
|
||||||
assert_valid
|
assert_valid
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "allows providing custom name via options" do
|
||||||
|
subject.synced_folder(".", "/vagrant", name: "my-vagrant-folder")
|
||||||
|
sf = subject.synced_folders
|
||||||
|
expect(sf).to have_key("my-vagrant-folder")
|
||||||
|
expect(sf["my-vagrant-folder"][:guestpath]).to eq("/vagrant")
|
||||||
|
expect(sf["my-vagrant-folder"][:hostpath]).to eq(".")
|
||||||
|
end
|
||||||
|
|
||||||
|
it "allows providing custom name without guest path" do
|
||||||
|
subject.synced_folder(".", name: "my-vagrant-folder")
|
||||||
|
sf = subject.synced_folders
|
||||||
|
expect(sf).to have_key("my-vagrant-folder")
|
||||||
|
expect(sf["my-vagrant-folder"][:hostpath]).to eq(".")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#usable_port_range" do
|
describe "#usable_port_range" do
|
||||||
|
|
Loading…
Reference in New Issue