upgrade shell - option to specify extensions

This commit is contained in:
evilbloodydemon 2010-12-11 18:14:54 +03:00
parent d414755036
commit c1d99017e9

View file

@ -71,17 +71,22 @@ class UpgradeShell extends Shell {
$this->_paths = array(App::pluginPath($this->params['plugin'])); $this->_paths = array(App::pluginPath($this->params['plugin']));
} }
$this->_findFiles(); $extensions = 'php|ctp|thtml|inc|tpl';
if (!empty($this->params['ext'])) {
$extensions = $this->params['ext'];
}
$this->_findFiles($extensions);
foreach ($this->_files as $file) { foreach ($this->_files as $file) {
$this->out('Updating ' . $file . '...', 1, Shell::VERBOSE); $this->out('Updating ' . $file . '...', 1, Shell::VERBOSE);
$this->_updateFile($file, $patterns); $this->_updateFile($file, $patterns);
} }
} }
protected function _findFiles($pattern = '') { protected function _findFiles($extensions = '', $pattern = '') {
foreach ($this->_paths as $path) { foreach ($this->_paths as $path) {
$Folder = new Folder($path); $Folder = new Folder($path);
$files = $Folder->findRecursive('.*\.(php|ctp|thtml|inc|tpl)', true); $files = $Folder->findRecursive(".*\.($extensions)", true);
if (!empty($pattern)) { if (!empty($pattern)) {
foreach ($files as $i => $file) { foreach ($files as $i => $file) {
if (preg_match($pattern, $file)) { if (preg_match($pattern, $file)) {
@ -117,22 +122,21 @@ class UpgradeShell extends Shell {
* @return void * @return void
*/ */
function getOptionParser() { function getOptionParser() {
$subcommandParser = array(
'options' => array(
'plugin' => array('short' => 'p', 'help' => __('The plugin to update.')),
'ext' => array('short' => 'e', 'help' => __('The extension(s) to search.')),
)
);
return parent::getOptionParser() return parent::getOptionParser()
->addSubcommand('i18n', array( ->addSubcommand('i18n', array(
'help' => 'Update the i18n translation method calls.', 'help' => 'Update the i18n translation method calls.',
'parser' => array( 'parser' => $subcommandParser
'options' => array(
'plugin' => array('short' => 'p', 'help' => __('The plugin to update.'))
)
)
)) ))
->addSubcommand('helpers', array( ->addSubcommand('helpers', array(
'help' => 'Update calls to helpers.', 'help' => 'Update calls to helpers.',
'parser' => array( 'parser' => $subcommandParser
'options' => array(
'plugin' => array('short' => 'p', 'help' => __('The plugin to update.'))
)
)
)); ));
} }
} }