Class: Wordmove::Hook::Remote

Inherits:
Object
  • Object
show all
Defined in:
lib/wordmove/hook.rb

Class Method Summary collapse

Class Method Details

.loggerObject



89
90
91
# File 'lib/wordmove/hook.rb', line 89

def self.logger
  parent.logger
end

.run(commands, options, simulate = false) ⇒ Object



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/wordmove/hook.rb', line 93

def self.run(commands, options, simulate = false)
  logger.task "Running remote hooks"

  ssh_options = options[:ssh]
  wordpress_path = options[:wordpress_path]

  copier = Photocopier::SSH.new(ssh_options).tap { |c| c.logger = logger }
  commands.each do |command|
    logger.task_step false, "Exec command: #{command}"
    return true if simulate

    stdout, stderr, exit_code =
      copier.exec!("bash -l -c 'cd #{wordpress_path} && #{command}'")

    if exit_code.zero?
      logger.task_step false, "Output: #{stdout}"
      logger.success ""
    else
      logger.task_step false, "Output: #{stderr}"
      logger.error "Error code #{exit_code}"
    end
  end
end