diff --git a/plugins/hosts/darwin/cap/rdp.rb b/plugins/hosts/darwin/cap/rdp.rb index 93ff71c31..d3df31d05 100644 --- a/plugins/hosts/darwin/cap/rdp.rb +++ b/plugins/hosts/darwin/cap/rdp.rb @@ -8,6 +8,15 @@ module VagrantPlugins module Cap class RDP def self.rdp_client(env, rdp_info) + config_path = self.generate_config_file(rdp_info) + Vagrant::Util::Subprocess.execute("open", config_path.to_s) + end + + protected + + # Generates an RDP connection file and returns the resulting path. + # @return [String] + def self.generate_config_file(rdp_info) opts = { "drivestoredirect:s" => "*", "full address:s" => "#{rdp_info[:host]}:#{rdp_info[:port]}", @@ -22,10 +31,15 @@ module VagrantPlugins opts.each do |k, v| f.puts("#{k}:#{v}") end + + if rdp_info[:extra_args] + rdp_info[:extra_args].each do |arg| + f.puts("#{arg}") + end + end end - # Launch it - Vagrant::Util::Subprocess.execute("open", config_path.to_s) + return config_path end end end diff --git a/test/unit/plugins/hosts/darwin/cap/rdp_test.rb b/test/unit/plugins/hosts/darwin/cap/rdp_test.rb new file mode 100644 index 000000000..cc6b1bade --- /dev/null +++ b/test/unit/plugins/hosts/darwin/cap/rdp_test.rb @@ -0,0 +1,36 @@ +require_relative "../../../../base" + +require_relative "../../../../../../plugins/hosts/darwin/cap/rdp" + +describe VagrantPlugins::HostDarwin::Cap::RDP do + let(:rdp_info) do + { + host: "host", + port: "port", + username: "username", + } + end + + it "includes the default options" do + path = described_class.generate_config_file(rdp_info) + result = File.read(path) + expect(result).to match("drivestoredirect:s:*") + expect(result).to match("full address:s:host:port") + expect(result).to match("prompt for credentials:i:1") + expect(result).to match("username:s:username") + end + + it "includes extra RDP arguments" do + rdp_info.merge!(extra_args: ["screen mode id:i:0"]) + path = described_class.generate_config_file(rdp_info) + result = File.read(path) + expect(result).to match("screen mode id:i:0") + end + + it "opens the RDP file" do + env = double(:env) + allow(described_class).to receive(:generate_config_file).and_return("/path") + expect(Vagrant::Util::Subprocess).to receive(:execute).with("open", "/path") + described_class.rdp_client(env, rdp_info) + end +end diff --git a/website/source/docs/cli/rdp.html.md b/website/source/docs/cli/rdp.html.md index 5907b6cf1..cc95a57b4 100644 --- a/website/source/docs/cli/rdp.html.md +++ b/website/source/docs/cli/rdp.html.md @@ -23,8 +23,21 @@ these through. For example: ``` $ vagrant rdp -- /span -... ``` The above command on Windows will execute `mstsc.exe /span config.rdp`, allowing your RDP to span multiple desktops. + + +On Darwin hosts, such as Mac OS X, the additional arguments are added to the +generated RDP configuration file. Since these files can contain multiple options +with different spacing, you _must_ quote multiple arguments. For example: + +``` +$ vagrant rdp -- "screen mode id:i:0" "other config:s:value" +``` + +Note that as of the publishing of this guide, the Microsoft RDP Client for Mac +does _not_ perform validation on the configuration file. This means if you +specify an invalid configuration option or make a typographical error, the +client will silently ignore the error and continue!