Class: VagrantSymfony::Command::CommandInVm
- Inherits:
-
Object
- Object
- VagrantSymfony::Command::CommandInVm
- Defined in:
- lib/vagrant-symfony/command/commandinvm.rb
Direct Known Subclasses
Instance Method Summary collapse
- #execute ⇒ Object
- #in_working_directory(vm, cmd) ⇒ Object
- #run_command(vm, cmd) ⇒ Object
- #run_interactive_command(vm, cmd) ⇒ Object
- #support_color ⇒ Object
- #working_directory(vm) ⇒ Object
Instance Method Details
#execute ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/vagrant-symfony/command/commandinvm.rb', line 7 def execute with_target_vms do |vm| if vm.state.id == :running cmd = build_command(vm) if interactive run_interactive_command(vm, cmd) else run_command(vm, cmd) end end end end |
#in_working_directory(vm, cmd) ⇒ Object
59 60 61 62 |
# File 'lib/vagrant-symfony/command/commandinvm.rb', line 59 def in_working_directory(vm, cmd) wd = working_directory(vm) "(cd #{wd}; #{cmd})" end |
#run_command(vm, cmd) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/vagrant-symfony/command/commandinvm.rb', line 46 def run_command(vm, cmd) communicator = vm.communicate if communicator.ready? exit_status = communicator.execute(cmd, :error_check => false) do |type, data| channel = type == :stdout ? :out : :error @env.ui.info(data.to_s, :prefix => false, :new_line => false, :channel => channel) end else @env.ui.error("Could not execute command") end exit exit_status end |
#run_interactive_command(vm, cmd) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/vagrant-symfony/command/commandinvm.rb', line 28 def run_interactive_command(vm, cmd) ssh_bin = VagrantSymfony::Which.which('ssh') if ssh_bin != nil info = vm.ssh_info args = [ info[:host], '-t', '-p', info[:port].to_s, '-l', info[:username], '-i', info[:private_key_path], '-o', 'LogLevel=QUIET', '--', cmd ] Vagrant::Util::SafeExec.exec('ssh', *args) end run_command(vm, cmd) end |
#support_color ⇒ Object
20 21 22 |
# File 'lib/vagrant-symfony/command/commandinvm.rb', line 20 def support_color ENV.include?('TERM') && ENV['TERM'].include?('color') end |
#working_directory(vm) ⇒ Object
24 25 26 |
# File 'lib/vagrant-symfony/command/commandinvm.rb', line 24 def working_directory(vm) vm.config.symfony.root end |