Skip to content

Commit d0e8bac

Browse files
committed
Merge branch 'develop'
2 parents b9fed61 + daae25b commit d0e8bac

File tree

7 files changed

+150
-0
lines changed

7 files changed

+150
-0
lines changed

.distignore

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
.DS_Store
2+
.git
3+
.gitignore
4+
.gitlab-ci.yml
5+
.editorconfig
6+
.travis.yml
7+
behat.yml
8+
circle.yml
9+
bin/
10+
features/
11+
utils/
12+
*.zip
13+
*.tar.gz
14+
*.swp
15+
*.txt
16+
*.log

.editorconfig

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# This file is for unifying the coding style for different editors and IDEs
2+
# editorconfig.org
3+
4+
# WordPress Coding Standards
5+
# https://make.wordpress.org/core/handbook/coding-standards/
6+
7+
root = true
8+
9+
[*]
10+
charset = utf-8
11+
end_of_line = lf
12+
insert_final_newline = true
13+
trim_trailing_whitespace = true
14+
indent_style = tab
15+
16+
[{.jshintrc,*.json,*.yml,*.feature}]
17+
indent_style = space
18+
indent_size = 2
19+
20+
[{*.txt,wp-config-sample.php}]
21+
end_of_line = crlf
22+
23+
[composer.json]
24+
indent_style = space
25+
indent_size = 4

.gitignore

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
.DS_Store
2+
wp-cli.local.yml
3+
node_modules/
4+
vendor/
5+
*.zip
6+
*.tar.gz
7+
*.swp
8+
*.txt
9+
*.log
10+
composer.lock
11+
.idea
12+
*.db

composer.json

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "easyengine/shell-command",
3+
"description": "Shell to run helpful commands inside containers.",
4+
"type": "ee-cli-package",
5+
"homepage": "https://github.com/easyengine/shell-command",
6+
"license": "MIT",
7+
"authors": [],
8+
"minimum-stability": "dev",
9+
"prefer-stable": true,
10+
"autoload": {
11+
"psr-4": {
12+
"": "src/"
13+
},
14+
"files": [ "shell-command.php" ]
15+
},
16+
"extra": {
17+
"branch-alias": {
18+
"dev-master": "1.x-dev"
19+
},
20+
"bundled": true,
21+
"commands": [
22+
"shell"
23+
]
24+
}
25+
}

ee.yml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
require:
2+
- shell-command.php

shell-command.php

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
if ( ! class_exists( 'EE' ) ) {
4+
return;
5+
}
6+
7+
$autoload = dirname( __FILE__ ) . '/vendor/autoload.php';
8+
if ( file_exists( $autoload ) ) {
9+
require_once $autoload;
10+
}
11+
12+
EE::add_command( 'shell', 'Shell_Command' );

src/Shell_Command.php

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
/**
4+
* Executes wp-cli command on a site.
5+
*
6+
* ## EXAMPLES
7+
*
8+
* # Create simple WordPress site
9+
* $ ee wp test.local plugin list
10+
*
11+
* @package ee-cli
12+
*/
13+
14+
use EE\Utils;
15+
16+
class Shell_Command extends EE_Command {
17+
18+
/**
19+
* Brings up a shell to run wp-cli, composer etc.
20+
*
21+
* ## OPTIONS
22+
*
23+
* [<site-name>]
24+
* : Name of website to run shell on.
25+
*/
26+
public function __invoke( $args ) {
27+
EE\Utils\delem_log( 'ee shell start' );
28+
$args = EE\Utils\set_site_arg( $args, 'shell' );
29+
$site_name = EE\Utils\remove_trailing_slash( $args[0] );
30+
if ( EE::db()::site_in_db( $site_name ) ) {
31+
$db_select = EE::db()::select( ['site_path'], ['sitename' => $site_name]);
32+
$site_root = $db_select[0]['site_path'];
33+
} else {
34+
EE::error( "Site $site_name does not exist." );
35+
}
36+
chdir($site_root);
37+
$this->run( "docker-compose exec --user='www-data' php bash" );
38+
EE\Utils\delem_log( 'ee shell end' );
39+
}
40+
41+
private function run( $cmd, $descriptors = null ) {
42+
EE\Utils\check_proc_available( 'ee_shell' );
43+
if ( ! $descriptors ) {
44+
$descriptors = array( STDIN, STDOUT, STDERR );
45+
}
46+
47+
$final_cmd = EE\Utils\force_env_on_nix_systems( $cmd );
48+
$proc = EE\Utils\proc_open_compat( $final_cmd, $descriptors, $pipes );
49+
if ( ! $proc ) {
50+
exit( 1 );
51+
}
52+
$r = proc_close( $proc );
53+
if ( $r ) {
54+
exit( $r );
55+
}
56+
}
57+
58+
}

0 commit comments

Comments
 (0)