Class: Hem::Lib::Vm::Command
- Inherits:
-
Object
- Object
- Hem::Lib::Vm::Command
- Defined in:
- lib/hem/lib/vm/command.rb
Constant Summary collapse
- @@vm_inspector =
Inspector.new
Class Attribute Summary collapse
-
.vm_inspector ⇒ Object
Returns the value of attribute vm_inspector.
Instance Attribute Summary collapse
-
#command ⇒ Object
Returns the value of attribute command.
-
#opts ⇒ Object
Returns the value of attribute opts.
Instance Method Summary collapse
- #<(cmd) ⇒ Object
- #<<(cmd) ⇒ Object
-
#initialize(command, opts = {}) ⇒ Command
constructor
A new instance of Command.
- #pipe(cmd, pipe_opts = {}) ⇒ Object
- #run ⇒ Object
-
#to_s ⇒ Object
TODO Speed up Vagrant SSH connections May need to be disabled for windows (mm_send_fd: UsePrivilegeSeparation=yes not supported) gist.github.com/jedi4ever/5657094.
- #to_str ⇒ Object
Constructor Details
#initialize(command, opts = {}) ⇒ Command
Returns a new instance of Command.
12 13 14 15 16 17 18 19 20 |
# File 'lib/hem/lib/vm/command.rb', line 12 def initialize command, opts = {} @command = command @opts = { :auto_echo => false, :psuedo_tty => false, :pwd => opts[:pwd] || @@vm_inspector.project_mount_path, :append => '' }.merge(opts) end |
Class Attribute Details
.vm_inspector ⇒ Object
Returns the value of attribute vm_inspector.
6 7 8 |
# File 'lib/hem/lib/vm/command.rb', line 6 def vm_inspector @vm_inspector end |
Instance Attribute Details
#command ⇒ Object
Returns the value of attribute command.
10 11 12 |
# File 'lib/hem/lib/vm/command.rb', line 10 def command @command end |
#opts ⇒ Object
Returns the value of attribute opts.
10 11 12 |
# File 'lib/hem/lib/vm/command.rb', line 10 def opts @opts end |
Instance Method Details
#<(cmd) ⇒ Object
42 43 44 |
# File 'lib/hem/lib/vm/command.rb', line 42 def < cmd pipe cmd, :on => :vm end |
#<<(cmd) ⇒ Object
38 39 40 |
# File 'lib/hem/lib/vm/command.rb', line 38 def << cmd pipe cmd, :on => :host end |
#pipe(cmd, pipe_opts = {}) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/hem/lib/vm/command.rb', line 22 def pipe cmd, pipe_opts = {} pipe_opts = pipe_opts.merge({ :on => :vm }) cmd = "echo #{cmd.shellescape}" if @opts[:auto_echo] case pipe_opts[:on] when :vm @pipe_in_vm = cmd when :host @pipe = cmd else raise "Unknown pipe source: #{pipe_opts[:on]}" end @opts[:psuedo_tty] = false return self end |
#run ⇒ Object
46 47 48 49 |
# File 'lib/hem/lib/vm/command.rb', line 46 def run return if @command.nil? Hem::Helper.shell to_s, @opts end |
#to_s ⇒ Object
TODO Speed up Vagrant SSH connections May need to be disabled for windows (mm_send_fd: UsePrivilegeSeparation=yes not supported) gist.github.com/jedi4ever/5657094
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/hem/lib/vm/command.rb', line 55 def to_s require 'tempfile' config = ::Tempfile.new 'hem_ssh_config' config.write @@vm_inspector.ssh_config config.close psuedo_tty = opts[:psuedo_tty] ? '-t' : '' ssh_command = [ 'ssh', "-F #{config.path.shellescape}", psuedo_tty, 'default' ].join(' ') pwd_set_command = " -- \"cd #{@opts[:pwd].shellescape}; exec /bin/bash" vm_command = [ @pipe_in_vm.nil? ? nil : @pipe_in_vm.gsub(/(\\+)/, '\\\\\1'), @command ].compact.join(' | ') command = [ ssh_command + pwd_set_command, vm_command.empty? ? nil : vm_command.shellescape ].compact.join(' -c ') + "#{@opts[:append].shellescape}\"" [ @pipe, command ].compact.join(' | ') end |
#to_str ⇒ Object
88 89 90 |
# File 'lib/hem/lib/vm/command.rb', line 88 def to_str to_s end |