/** * Launch another Terminus command using the runtime arguments for the * current process * * @param string $command Command to call * @param array $args Positional arguments to use * @param array $assoc_args Associative arguments to use * @param bool $exit_on_error True to exit if the command returns error * @return int The command exit status */ public static function launchSelf($command, $args = array(), $assoc_args = array(), $exit_on_error = true) { if (isset($GLOBALS['argv'])) { $script_path = $GLOBALS['argv'][0]; } else { $script_path = __DIR__ . '/boot-fs.php'; } $php_bin = '"' . self::getPhpBinary() . '"'; $script_path = '"' . $script_path . '"'; $escaped_args = array_map('escapeshellarg', $args); $args = implode(' ', $escaped_args); $assoc_args = Utils\assocArgsToStr($assoc_args); $full_command = "{$php_bin} {$script_path} {$command} {$args} {$assoc_args}"; $status = self::launch($full_command, $exit_on_error); return $status; }
/** * Launch another Terminus command using the runtime arguments for the * current process * * @param string $command Command to call * @param array $args Positional arguments to use * @param array $assoc_args Associative arguments to use * @param bool $exit_on_error True to exit if the command returns error * @return int The command exit status */ public static function launchSelf($command, $args = array(), $assoc_args = array(), $exit_on_error = true) { $reused_runtime_args = array('path', 'url', 'user', 'allow-root'); foreach ($reused_runtime_args as $key) { if (array_key_exists($key, self::getRunner()->config)) { $assoc_args[$key] = self::getRunner()->config[$key]; } } if (Terminus::isTest()) { $script_path = __DIR__ . '/boot-fs.php'; } else { $script_path = $GLOBALS['argv'][0]; } $php_bin = '"' . self::getPhpBinary() . '"'; $script_path = '"' . $script_path . '"'; $escaped_args = array_map('escapeshellarg', $args); $args = implode(' ', $escaped_args); $assoc_args = Utils\assocArgsToStr($assoc_args); $full_command = "{$php_bin} {$script_path} {$command} {$args} {$assoc_args}"; $status = self::launch($full_command, $exit_on_error); return $status; }
public function testAssocArgsToStr() { $assoc_args = ['argument' => 'value', 'flag' => true]; $args_string = Utils\assocArgsToStr($assoc_args); $this->assertEquals($args_string, " --argument='value' --flag"); }