Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
mbtamuli committed Jun 25, 2018
2 parents b9fed61 + daae25b commit d0e8bac
Show file tree
Hide file tree
Showing 7 changed files with 150 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .distignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.DS_Store
.git
.gitignore
.gitlab-ci.yml
.editorconfig
.travis.yml
behat.yml
circle.yml
bin/
features/
utils/
*.zip
*.tar.gz
*.swp
*.txt
*.log
25 changes: 25 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# This file is for unifying the coding style for different editors and IDEs
# editorconfig.org

# WordPress Coding Standards
# https://make.wordpress.org/core/handbook/coding-standards/

root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = tab

[{.jshintrc,*.json,*.yml,*.feature}]
indent_style = space
indent_size = 2

[{*.txt,wp-config-sample.php}]
end_of_line = crlf

[composer.json]
indent_style = space
indent_size = 4
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.DS_Store
wp-cli.local.yml
node_modules/
vendor/
*.zip
*.tar.gz
*.swp
*.txt
*.log
composer.lock
.idea
*.db
25 changes: 25 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "easyengine/shell-command",
"description": "Shell to run helpful commands inside containers.",
"type": "ee-cli-package",
"homepage": "https://github.com/easyengine/shell-command",
"license": "MIT",
"authors": [],
"minimum-stability": "dev",
"prefer-stable": true,
"autoload": {
"psr-4": {
"": "src/"
},
"files": [ "shell-command.php" ]
},
"extra": {
"branch-alias": {
"dev-master": "1.x-dev"
},
"bundled": true,
"commands": [
"shell"
]
}
}
2 changes: 2 additions & 0 deletions ee.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require:
- shell-command.php
12 changes: 12 additions & 0 deletions shell-command.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

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

$autoload = dirname( __FILE__ ) . '/vendor/autoload.php';
if ( file_exists( $autoload ) ) {
require_once $autoload;
}

EE::add_command( 'shell', 'Shell_Command' );
58 changes: 58 additions & 0 deletions src/Shell_Command.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

/**
* Executes wp-cli command on a site.
*
* ## EXAMPLES
*
* # Create simple WordPress site
* $ ee wp test.local plugin list
*
* @package ee-cli
*/

use EE\Utils;

class Shell_Command extends EE_Command {

/**
* Brings up a shell to run wp-cli, composer etc.
*
* ## OPTIONS
*
* [<site-name>]
* : Name of website to run shell on.
*/
public function __invoke( $args ) {
EE\Utils\delem_log( 'ee shell start' );
$args = EE\Utils\set_site_arg( $args, 'shell' );
$site_name = EE\Utils\remove_trailing_slash( $args[0] );
if ( EE::db()::site_in_db( $site_name ) ) {
$db_select = EE::db()::select( ['site_path'], ['sitename' => $site_name]);
$site_root = $db_select[0]['site_path'];
} else {
EE::error( "Site $site_name does not exist." );
}
chdir($site_root);
$this->run( "docker-compose exec --user='www-data' php bash" );
EE\Utils\delem_log( 'ee shell end' );
}

private function run( $cmd, $descriptors = null ) {
EE\Utils\check_proc_available( 'ee_shell' );
if ( ! $descriptors ) {
$descriptors = array( STDIN, STDOUT, STDERR );
}

$final_cmd = EE\Utils\force_env_on_nix_systems( $cmd );
$proc = EE\Utils\proc_open_compat( $final_cmd, $descriptors, $pipes );
if ( ! $proc ) {
exit( 1 );
}
$r = proc_close( $proc );
if ( $r ) {
exit( $r );
}
}

}

0 comments on commit d0e8bac

Please sign in to comment.