Skip to content
Permalink
Browse files

Allow loading and unloading plugins for bootstrap_cli

  • Loading branch information...
dereuromark committed Nov 27, 2016
1 parent a30ee07 commit 35d6df54bd9c34585fed1dc47a05491f9bbfd001
Showing with 29 additions and 9 deletions.
  1. +13 −3 src/Shell/Task/LoadTask.php
  2. +16 −6 src/Shell/Task/UnloadTask.php
@@ -38,9 +38,14 @@ class LoadTask extends Shell
*/
public function main($plugin = null)
{
$this->bootstrap = ROOT . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'bootstrap.php';
$filename = 'bootstrap';
if ($this->params['cli']) {
$filename .= '_cli';
}
$this->bootstrap = ROOT . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . $filename . '.php';
if (empty($plugin)) {
if (!$plugin) {
$this->err('You must provide a plugin name in CamelCase format.');
$this->err('To load an "Example" plugin, run `cake plugin load Example`.');
@@ -109,11 +114,16 @@ public function getOptionParser()
'default' => false,
])
->addOption('autoload', [
'help' => 'Will autoload the plugin using CakePHP. ' .
'help' => 'Will autoload the plugin using CakePHP.' .
'Set to true if you are not using composer to autoload your plugin.',
'boolean' => true,
'default' => false,
])
->addOption('cli', [
'help' => 'Use the bootstrap_cli file.',
'boolean' => true,
'default' => false,
])
->addArgument('plugin', [
'help' => 'Name of the plugin to load.',
]);
@@ -38,9 +38,14 @@ class UnloadTask extends Shell
*/
public function main($plugin = null)
{
$this->bootstrap = ROOT . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'bootstrap.php';
$filename = 'bootstrap';
if ($this->params['cli']) {
$filename .= '_cli';
}
$this->bootstrap = ROOT . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . $filename . '.php';
if (empty($plugin)) {
if (!$plugin) {
$this->err('You must provide a plugin name in CamelCase format.');
$this->err('To unload an "Example" plugin, run `cake plugin unload Example`.');
@@ -58,7 +63,7 @@ public function main($plugin = null)
*/
protected function _modifyBootstrap($plugin)
{
$finder = "/\nPlugin::load\((.|.\n|\n\s\s|\n\t|)+'$plugin'(.|.\n|)+\);\n/";
$finder = "@\nPlugin::load\((.|.\n|\n\s\s|\n\t|)+'$plugin'(.|.\n|)+\);\n@";
$bootstrap = new File($this->bootstrap, false);
$contents = $bootstrap->read();
@@ -86,9 +91,14 @@ public function getOptionParser()
{
$parser = parent::getOptionParser();
$parser->addArgument('plugin', [
'help' => 'Name of the plugin to load.',
]);
$parser->addOption('cli', [
'help' => 'Use the bootstrap_cli file.',
'boolean' => true,
'default' => false,
])
->addArgument('plugin', [
'help' => 'Name of the plugin to load.',
]);
return $parser;
}

0 comments on commit 35d6df5

Please sign in to comment.
You can’t perform that action at this time.