| 1 |
<?php |
| 2 |
|
| 3 |
class SM_CLI { |
| 4 |
|
| 5 |
/** |
| 6 |
* Launch an external process that takes over I/O. |
| 7 |
* |
| 8 |
* @param string Command to call |
| 9 |
* @param bool Whether to exit if the command returns an error status |
| 10 |
* @param bool Whether to return an exit status (default) or detailed execution results |
| 11 |
* |
| 12 |
* @return int|ProcessRun The command exit status, or a ProcessRun instance |
| 13 |
*/ |
| 14 |
public static function launch( $command, $exit_on_error = true, $return_detailed = false ) { |
| 15 |
if( !class_exists( 'SM_CLI_Process' ) ) { |
| 16 |
require_once( dirname( __FILE__ ) . '/class-sm-cli-process.php' ); |
| 17 |
} |
| 18 |
|
| 19 |
$proc = SM_CLI_Process::create( $command ); |
| 20 |
$results = $proc->run(); |
| 21 |
|
| 22 |
if ( $results->return_code && $exit_on_error ) |
| 23 |
exit( $results->return_code ); |
| 24 |
|
| 25 |
if ( $return_detailed ) { |
| 26 |
return $results; |
| 27 |
} else { |
| 28 |
return $results->return_code; |
| 29 |
} |
| 30 |
} |
| 31 |
|
| 32 |
} |