Skip to content

Commit

Permalink
Allow loading and unloading plugins for bootstrap_cli
Browse files Browse the repository at this point in the history
  • Loading branch information
dereuromark committed Nov 27, 2016
1 parent a30ee07 commit 35d6df5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
16 changes: 13 additions & 3 deletions src/Shell/Task/LoadTask.php
Expand Up @@ -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`.');

Expand Down Expand Up @@ -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.',
]);
Expand Down
22 changes: 16 additions & 6 deletions src/Shell/Task/UnloadTask.php
Expand Up @@ -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`.');

Expand All @@ -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();
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 35d6df5

Please sign in to comment.