11<?php
22
33/**
4- * Executes wp-cli command on a site .
4+ * Brings up a shell to run wp-cli, composer etc .
55 *
66 * ## EXAMPLES
77 *
8- * # Create simple WordPress site
9- * $ ee wp test.local plugin list
8+ * # Open shell of example.com
9+ * $ ee shell example.com
1010 *
1111 * @package ee-cli
1212 */
@@ -30,13 +30,14 @@ public function __invoke( $args ) {
3030 $ args = auto_site_name ( $ args , 'shell ' , '' );
3131 $ site_name = EE \Utils \remove_trailing_slash ( $ args [0 ] );
3232
33- $ site = Site::find ( $ site_name, [ ' site_enabled ' , ' site_fs_path ' ] );
33+ $ site = Site::find ( $ site_name );
3434
3535 if ( ! $ site || ! $ site ->site_enabled ) {
3636 EE ::error ( "Site $ site_name does not exist or is not enabled. " );
3737 }
3838
3939 chdir ( $ site ->site_fs_path );
40+ $ this ->check_shell_available ( 'php ' , $ site );
4041 $ this ->run ( "docker-compose exec --user='www-data' php bash " );
4142 EE \Utils \delem_log ( 'ee shell end ' );
4243 }
@@ -64,4 +65,21 @@ private function run( $cmd, $descriptors = null ) {
6465 }
6566 }
6667
68+ /**
69+ * Function to check if container supporting shell is present in docker-compose.yml or not.
70+ *
71+ * @param string $shell_container Container to be checked.
72+ * @param Object $site Contains relevant site info.
73+ */
74+ private function check_shell_available ( $ shell_container , $ site ) {
75+
76+ $ launch = EE ::launch ( 'docker-compose config --services ' );
77+ $ services = explode ( PHP_EOL , trim ( $ launch ->stdout ) );
78+ if ( ! in_array ( $ shell_container , $ services , true ) ) {
79+ EE ::debug ( 'Site type: ' . $ site ->site_type );
80+ EE ::debug ( 'Site command: ' . $ site ->app_sub_type );
81+ EE ::error ( sprintf ( '%s site does not have support to launch %s shell. ' , $ shell_container , $ site ->site_url ) );
82+ }
83+ }
84+
6785}
0 commit comments