module Shuttle::WordpressCli

Constants

CLI_GIT
CLI_PATH

Public Instance Methods

cli_checkout_code() click to toggle source

Checkout a proper wp-cli revision. By default it’ll install latest available tag from git. That’s considered a stable version. To install latest code, set ‘cli` option in config:

wordpress:
  cli: master
# File lib/shuttle/deployment/wordpress/cli.rb, line 35
def cli_checkout_code
  ssh.run("sudo git clone --recursive --quiet #{CLI_GIT} #{CLI_PATH}")

  if config.wordpress.cli.nil?
    tags = ssh.capture("cd #{CLI_PATH} && git tag").split("\n").map(&:strip).reverse
    tag  = tags.first
    rev  = ssh.capture("cd #{CLI_PATH} && git rev-parse #{tag}").strip
  else
    tag = config.wordpress.cli

    if tag =~ /^[\d\.]+$/ # version def
      tag = "v#{tag}" unless tag =~ /v[\d]+/
    end
    
    rev = tag
  end

  res = ssh.run("cd #{CLI_PATH} && sudo git checkout #{rev}")

  if res.failure?
    error "Unable to checkout revision #{rev}: #{res.output}"
  end

  #rev, tag
end
cli_install() click to toggle source
# File lib/shuttle/deployment/wordpress/cli.rb, line 10
def cli_install
  log "Installing WordPress CLI"

  rev, tag = cli_checkout_code

  res = ssh.run("cd #{CLI_PATH} && sudo utils/dev-build")

  if res.failure?
    error "Unable to build cli: #{res.output}"
  end
  
  if cli_installed?
    log "WordPress CLI (#{tag}) installed"
  else
    error "Wordpress CLI installation failed"
  end
end
cli_installed?() click to toggle source
# File lib/shuttle/deployment/wordpress/cli.rb, line 6
def cli_installed?
  ssh.run("which wp").success?
end
cli_uninstall() click to toggle source
# File lib/shuttle/deployment/wordpress/cli.rb, line 61
def cli_uninstall
  ssh.run("sudo rm $(which wp)")
  ssh.run("sudo rm -rf #{CLI_PATH}")
end