Skip to content

Commit

Permalink
Add browse command (#289)
Browse files Browse the repository at this point in the history
  • Loading branch information
miya0001 authored Nov 7, 2017
1 parent 13cdcf5 commit 3987478
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 9 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
/_site
/npm-debug.log
/package.box
/playbook.retry
/provision/playbook.retry
/provision-post.sh
/provision-pre.sh
/site.yml
/test.json
/vendor
/wp-cli.yml
/wordpress
/wp-cli
2 changes: 2 additions & 0 deletions bin/run-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ vccw/vccw-xenial64:latest \

docker exec --tty ${VCCW_HOSTNAME} env TERM=xterm chown ubuntu:ubuntu ${VM_DIR}
docker exec --tty ${VCCW_HOSTNAME} env TERM=xterm chmod 777 ${VM_DIR}
docker exec --tty ${VCCW_HOSTNAME} env TERM=xterm mkdir ${VM_DIR}/wp-cli
docker exec --tty ${VCCW_HOSTNAME} env TERM=xterm chmod 777 ${VM_DIR}/wp-cli

docker exec --user ubuntu --tty ${VCCW_HOSTNAME} \
env TERM=xterm ansible-playbook ${VM_DIR}/provision/playbook.yml -e "$(ruby $RUBY)"
Expand Down
31 changes: 23 additions & 8 deletions provision/playbooks/commands.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,6 @@
file:
path: "{{ ansible_env.HOME }}/.wp-cli/"
state: directory
- name: Create a `~/.wp-cli/config.yml` on the Guest
template:
src: templates/guest-wp-cli-config.yml
dest: "{{ ansible_env.HOME }}/.wp-cli/config.yml"
- name: Create a `wp-cli.yml` to the host
template:
src: templates/wp-cli.yml
dest: "{{ vccw.vagrant_dir }}/wp-cli.yml"
- name: Install WP-CLI packages
become: no
shell: /bin/bash -lc "wp package install '{{ item }}'"
Expand All @@ -81,6 +73,18 @@
url: https://raw.githubusercontent.com/wp-cli/wp-cli/master/utils/wp-completion.bash
dest: "{{ ansible_env.HOME }}/.bash.d/wp-completion.sh"
force: yes
- name: Create `wp-cli` dir
become: yes
file:
path: "{{ vccw.vagrant_dir }}/wp-cli"
state: directory
- name: Place a `wp browse` command.
template:
src: templates/browse-command.php
dest: "{{ vccw.vagrant_dir }}/wp-cli/browse-command.php"
notify:
- wp-cli-config
- wp-cli-local-config

# Install Ruby gems
- name: Place a ~/.gemrc
Expand Down Expand Up @@ -143,3 +147,14 @@
state: absent
with_items:
- .wget-hsts

handlers:
- name: wp-cli-config
template:
src: templates/guest-wp-cli-config.yml
dest: "{{ ansible_env.HOME }}/.wp-cli/config.yml"
- name: wp-cli-local-config
template:
src: templates/wp-cli.yml
dest: "{{ vccw.vagrant_dir }}/wp-cli.yml"
force: no
34 changes: 34 additions & 0 deletions provision/playbooks/templates/browse-command.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

if ( ! class_exists( 'WP_CLI' ) ) {
return;
}

/**
* Open the website in your browser.
*
* ## Options
*
* [--wp-admin]
* : Open the dashboard.
*
* @when before_wp_load
*/
$browse_command = function( $_, $assoc_args ) {
$exec = 'xdg-open';
if ( 'DAR' === strtoupper( substr( PHP_OS, 0, 3 ) ) ) {
$exec = 'open';
}

$wp_admin = \WP_CLI\Utils\get_flag_value( $assoc_args, 'wp-admin' );

if ( true === $wp_admin ) {
$url = 'http://{{ vccw.hostname }}/wp-admin/';
} else {
$url = 'http://{{ vccw.hostname }}/';
}

passthru( $exec . ' ' . escapeshellarg( $url ) );
};

WP_CLI::add_command( 'browse', $browse_command );
2 changes: 2 additions & 0 deletions provision/playbooks/templates/wp-cli.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
require:
- wp-cli/browse-command.php
@{{ vccw.hostname }}:
ssh: vagrant:{{ vccw.hostname }}:{{ vccw.document_root }}

0 comments on commit 3987478

Please sign in to comment.