Skip to content

Commit 91f841a

Browse files
committed
Update checks in running commands
Signed-off-by: Riddhesh Sanghvi <[email protected]>
1 parent 0022322 commit 91f841a

File tree

1 file changed

+37
-17
lines changed

1 file changed

+37
-17
lines changed

php/EE/Runner.php

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -64,27 +64,47 @@ private function init_ee() {
6464

6565
if (
6666
! empty( $this->arguments ) &&
67-
( 'help' !== $this->arguments[0] )
68-
&& $this->arguments !== [ 'cli', 'version' ]
69-
)
70-
{
67+
( ! in_array( $this->arguments[0], [ 'cli', 'config', 'help' ], true ) )
68+
) {
69+
$this->check_requirements();
70+
$this->maybe_trigger_migration();
71+
}
72+
if ( [ 'cli', 'info' ] === $this->arguments && $this->check_requirements( false ) ) {
73+
$this->maybe_trigger_migration();
74+
}
75+
}
7176

72-
// Minimum requirement checks.
73-
$docker_running = 'docker ps > /dev/null';
74-
if ( ! EE::exec( $docker_running ) ) {
75-
EE::error( 'docker not installed or not running.' );
76-
}
77+
/**
78+
* Check EE requirements for required commands.
79+
*
80+
* @param bool $show_error To display error or to retutn status.
81+
*/
82+
public function check_requirements( $show_error = true ) {
7783

78-
$docker_compose_installed = 'command -v docker-compose > /dev/null';
79-
if ( ! EE::exec( $docker_compose_installed ) ) {
80-
EE::error( 'EasyEngine requires docker-compose.' );
81-
}
84+
$status = true;
8285

83-
if ( version_compare( PHP_VERSION, '7.2.0' ) < 0 ) {
84-
EE::error( 'EasyEngine requires minimum PHP 7.2.0 to run.' );
85-
}
86+
// Minimum requirement checks.
87+
$docker_running = 'docker ps > /dev/null';
88+
if ( ! EE::exec( $docker_running ) ) {
89+
$status = false;
90+
$error = 'Docker not installed or not running.';
91+
}
8692

87-
$this->maybe_trigger_migration();
93+
$docker_compose_installed = 'command -v docker-compose > /dev/null';
94+
if ( ! EE::exec( $docker_compose_installed ) ) {
95+
$status = false;
96+
$error = 'EasyEngine requires docker-compose.';
97+
}
98+
99+
if ( version_compare( PHP_VERSION, '7.2.0' ) < 0 ) {
100+
$status = false;
101+
$error = 'EasyEngine requires minimum PHP 7.2.0 to run.';
102+
}
103+
104+
if ( ! $show_error ) {
105+
return $status;
106+
} elseif ( ! $status ) {
107+
EE::error( $error );
88108
}
89109
}
90110

0 commit comments

Comments
 (0)