Class: VagrantPoderosa::Command
- Inherits:
-
Object
- Object
- VagrantPoderosa::Command
- Defined in:
- lib/vagrant-poderosa/command.rb
Class Method Summary collapse
Instance Method Summary collapse
- #create_shortcut(vm, ssh_info) ⇒ Object
- #do_process(commands) ⇒ Object
- #execute ⇒ Object
- #find_exe_path(path) ⇒ Object
Class Method Details
.synopsis ⇒ Object
7 8 9 |
# File 'lib/vagrant-poderosa/command.rb', line 7 def self.synopsis 'connects to machine via SSH using Poderosa' end |
Instance Method Details
#create_shortcut(vm, ssh_info) ⇒ Object
62 63 64 65 |
# File 'lib/vagrant-poderosa/command.rb', line 62 def create_shortcut(vm, ssh_info) require_relative 'shortcut' Shortcut.create_shortcut(vm, ssh_info) end |
#do_process(commands) ⇒ Object
67 68 69 70 |
# File 'lib/vagrant-poderosa/command.rb', line 67 def do_process(commands) pid = spawn(commands.join(' ')) Process.detach(pid) end |
#execute ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/vagrant-poderosa/command.rb', line 11 def execute opts = OptionParser.new do |opt| opt. = 'Usage: vagrant poderosa [vm-name...]' opt.separator '' end argv = (opts) return -1 unless argv with_target_vms(argv, single_target: true) do |vm| @config = vm.config.poderosa ssh_info = vm.ssh_info @logger.debug("ssh_info is #{ssh_info}") # If ssh_info is nil, the machine is not ready for ssh. fail Vagrant::Errors::SSHNotReady if ssh_info.nil? exe_path = find_exe_path(@config.exe_path) return -1 unless exe_path commands = [ "\"#{exe_path}\"", '-open', create_shortcut(vm, ssh_info) ] do_process(commands) end end |
#find_exe_path(path) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/vagrant-poderosa/command.rb', line 41 def find_exe_path(path) if !path.nil? return path if File.executable?(path) # search in PATH ENV['PATH'].split(File::PATH_SEPARATOR).each do |p| exe_path = Pathname(p) + path return exe_path.to_s if exe_path.executable? end else # search in PATH ENV['PATH'].split(File::PATH_SEPARATOR).each do |p| exe_path = Pathname(p) + 'Poderosa.exe' return exe_path.to_s if exe_path.executable? end end @env.ui.error("File is not found or executable. => #{path}") nil end |