Module: Shuttle::WordpressCli

Included in:
Wordpress
Defined in:
lib/shuttle/deployment/wordpress/cli.rb

Constant Summary collapse

CLI_GIT =
'https://github.com/wp-cli/wp-cli.git'
CLI_PATH =
'/usr/local/share/wp-cli'

Instance Method Summary collapse

Instance Method Details

#cli_checkout_codeObject

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


35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# 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_installObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# 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?Boolean

Returns:

  • (Boolean)


6
7
8
# File 'lib/shuttle/deployment/wordpress/cli.rb', line 6

def cli_installed?
  ssh.run("which wp").success?
end

#cli_uninstallObject



61
62
63
64
# 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