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
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -38,9 +38,14 @@ class LoadTask extends Shell
*/ */
public function main($plugin = null) 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('You must provide a plugin name in CamelCase format.');
$this->err('To load an "Example" plugin, run `cake plugin load Example`.'); $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, 'default' => false,
]) ])
->addOption('autoload', [ ->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.', 'Set to true if you are not using composer to autoload your plugin.',
'boolean' => true, 'boolean' => true,
'default' => false, 'default' => false,
]) ])
->addOption('cli', [
'help' => 'Use the bootstrap_cli file.',
'boolean' => true,
'default' => false,
])
->addArgument('plugin', [ ->addArgument('plugin', [
'help' => 'Name of the plugin to load.', 'help' => 'Name of the plugin to load.',
]); ]);
Expand Down
22 changes: 16 additions & 6 deletions src/Shell/Task/UnloadTask.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -38,9 +38,14 @@ class UnloadTask extends Shell
*/ */
public function main($plugin = null) 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('You must provide a plugin name in CamelCase format.');
$this->err('To unload an "Example" plugin, run `cake plugin unload Example`.'); $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) 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); $bootstrap = new File($this->bootstrap, false);
$contents = $bootstrap->read(); $contents = $bootstrap->read();
Expand Down Expand Up @@ -86,9 +91,14 @@ public function getOptionParser()
{ {
$parser = parent::getOptionParser(); $parser = parent::getOptionParser();


$parser->addArgument('plugin', [ $parser->addOption('cli', [
'help' => 'Name of the plugin to load.', 'help' => 'Use the bootstrap_cli file.',
]); 'boolean' => true,
'default' => false,
])
->addArgument('plugin', [
'help' => 'Name of the plugin to load.',
]);


return $parser; return $parser;
} }
Expand Down

0 comments on commit 35d6df5

Please sign in to comment.