Class: Wordmove::Hook::Remote

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

Class Method Summary collapse

Class Method Details

.loggerObject



103
104
105
# File 'lib/wordmove/hook.rb', line 103

def self.logger
  Wordmove::Hook.logger
end

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



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/wordmove/hook.rb', line 107

def self.run(command_hash, options, simulate = false)
  ssh_options = options[:ssh]
  wordpress_path = options[:wordpress_path]

  copier = Photocopier::SSH.new(ssh_options).tap { |c| c.logger = logger }

  logger.task_step false, "Exec command: #{command_hash[:command]}"
  return true if simulate

  stdout, stderr, exit_code =
    copier.exec!("cd #{wordpress_path} && #{command_hash[: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}"
    raise Wordmove::RemoteHookException unless command_hash[:raise].eql? false
  end
end