From 0e2c1fc2e9b1d727fbe4e08bf29e4a9e4b3c0e85 Mon Sep 17 00:00:00 2001 From: miya0001 Date: Tue, 15 Nov 2016 09:41:50 +0900 Subject: [PATCH 1/2] bug fix on phpunit --- bin/install-wp-tests.sh | 18 +++++++++++++++++- tests/bootstrap.php | 4 ---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/bin/install-wp-tests.sh b/bin/install-wp-tests.sh index 0fa5df4..0aaf09f 100644 --- a/bin/install-wp-tests.sh +++ b/bin/install-wp-tests.sh @@ -87,8 +87,24 @@ install_test_suite() { } install_db() { + # parse DB_HOST for port or socket references + local PARTS=(${DB_HOST//\:/ }) + local DB_HOSTNAME=${PARTS[0]}; + local DB_SOCK_OR_PORT=${PARTS[1]}; + local EXTRA="" + + if ! [ -z $DB_HOSTNAME ] ; then + if [ $(echo $DB_SOCK_OR_PORT | grep -e '^[0-9]\{1,\}$') ]; then + EXTRA=" --host=$DB_HOSTNAME --port=$DB_SOCK_OR_PORT --protocol=tcp" + elif ! [ -z $DB_SOCK_OR_PORT ] ; then + EXTRA=" --socket=$DB_SOCK_OR_PORT" + elif ! [ -z $DB_HOSTNAME ] ; then + EXTRA=" --host=$DB_HOSTNAME --protocol=tcp" + fi + fi + # create database - mysql -e 'CREATE DATABASE IF NOT EXISTS $DB_NAME;' -uroot + mysqladmin create $DB_NAME --user="$DB_USER" --password="$DB_PASS"$EXTRA } install_wp diff --git a/tests/bootstrap.php b/tests/bootstrap.php index de9976b..a110e18 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -1,13 +1,9 @@ Date: Wed, 16 Nov 2016 16:06:15 +0900 Subject: [PATCH 2/2] enables to customize template --- README.md | 6 ++++++ cli.php | 2 +- lib/functions.php | 22 ++++++++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 94c9401..b490eaa 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,12 @@ Once you've done so, you can install this package with: $ wp package install vccw/scaffold-vccw:@stable ``` +## Customize your default site.yml + +1. [Download default template from GitHub](https://raw.githubusercontent.com/vccw-team/scaffold-vccw/master/templates/site.yml.mustache). +2. Edit it. +3. Place it under the file name of `~/.wp-cli/vccw.yml.mustache`. + ## Usage ``` diff --git a/cli.php b/cli.php index 60dd0e3..246381e 100644 --- a/cli.php +++ b/cli.php @@ -106,7 +106,7 @@ public function __invoke( $args, $assoc_args ) } $sitefile = WP_CLI\Utils\mustache_render( - dirname( __FILE__ ) . '/templates/site.yml.mustache', + Scaffold_VCCW::get_yml_template(), array( 'host' => $assoc_args["host"], 'ip' => $assoc_args["ip"], diff --git a/lib/functions.php b/lib/functions.php index 88fd552..486ded6 100644 --- a/lib/functions.php +++ b/lib/functions.php @@ -4,6 +4,28 @@ class Scaffold_VCCW { + /** + * Get path to the mustache template. + * + * @return string Path to the template. + */ + public static function get_yml_template() + { + $home = getenv( 'HOME' ); + if ( !$home ) { + // sometime in windows $HOME is not defined + $home = getenv( 'HOMEDRIVE' ) . getenv( 'HOMEPATH' ); + } + + $config = $home . '/.wp-cli'; + + if ( is_file( $config . '/vccw.yml.mustache' ) ) { + return $config . '/vccw.yml.mustache'; + } else { + return dirname( __FILE__ ) . '/../templates/site.yml.mustache'; + } + } + /** * Get URL of the latest VCCW. *