From: Antonio Ospite Date: Mon, 28 Feb 2011 11:24:34 +0000 (+0100) Subject: dgrep has been merged in Drush Extras X-Git-Url: https://git.ao2.it/dgrep.git/commitdiff_plain/refs/heads/master?ds=inline dgrep has been merged in Drush Extras Remove the code and add a message redirecting users to the Drush Extras project page. --- diff --git a/README.txt b/README.txt new file mode 100644 index 0000000..66a3493 --- /dev/null +++ b/README.txt @@ -0,0 +1,4 @@ +dgrep has been merged in Drush Extras. + +Further development will take place in Drush Extras: +http://drupal.org/project/drush_extras diff --git a/TODO b/TODO deleted file mode 100644 index 817377f..0000000 --- a/TODO +++ /dev/null @@ -1,3 +0,0 @@ -Add more commands following php preg_* functions -Implement grepping on blog -Factor out common parts to share with a drupal "frontend" module diff --git a/dgrep.drush.inc b/dgrep.drush.inc deleted file mode 100644 index b5c603f..0000000 --- a/dgrep.drush.inc +++ /dev/null @@ -1,126 +0,0 @@ - - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * - * You can copy this file to any of the following - * 1. A .drush folder in your HOME folder. - * 2. Anywhere in a folder tree below an active module on your site. - * 3. /usr/share/drush/commands (configurable) - * 4. In an arbitrary folder specified with the --include option. - */ - -/** - * Implementation of hook_drush_command(). - */ -function dgrep_drush_command() { - $items = array(); - - $items['grep'] = array( - 'description' => "grep through content using PCREs.", - 'arguments' => array( - 'pattern' => 'The PCRE-style regular expression to match.', - ), - 'options' => array( - 'content-types' => 'Comma delimited list of content types to search into (node,comment,block).', - ), - 'examples' => array( - 'drush grep \'#https://[^"]*#\' --content-types=node', - ), - 'aliases' => array('dgrep'), - 'bootstrap' => DRUSH_BOOTSTRAP_DRUPAL_FULL, // XXX: maybe something less. - ); - - return $items; -} - -/** - * Implementation of hook_drush_help(). - */ -function dgrep_drush_help($section) { - switch ($section) { - case 'drush:grep': - return dt("This command will allow you to grep through content using PCREs."); - } -} - -/* - * Implementation of drush_hook_COMMAND_validate(). - */ -function drush_dgrep_grep_validate($pattern) { - $ret = @preg_match($pattern, ''); - if ($ret === FALSE) { - return drush_set_error(dt('Error: pattern should be a valid PCRE.')); - } -} - -/** - * This is where the action takes place. - */ -function drush_dgrep_grep($pattern) { - $content_types = drush_get_option('content-types'); - if ($content_types) { - $list = explode(',', $content_types); - } - else { - $list = array('node', 'comment', 'block'); - } - - if (in_array('node', $list)) { - $sql = 'SELECT nid FROM {node}'; - $nids = db_query($sql); - - while ($nid = db_result($nids)) { - $node = node_load($nid); - - $ret = preg_match($pattern, $node->body, $matches); - if ($ret) { - $nid_str = sprintf("%-4d", $nid); - drush_print('Node: '. $nid_str . "\tTitle: " . $node->title); - drush_print("\t\tURL: " . drupal_get_path_alias('node/'.$nid)); - drush_print("\t\tMatch: " . $matches[0]); - drush_print(); - } - } - } - - if (in_array('comment', $list)) { - $sql = 'SELECT cid FROM {comments}'; - $cids = db_query($sql); - - while ($cid = db_result($cids)) { - $comment = _comment_load($cid); - - $ret = preg_match($pattern, $comment->comment, $matches); - if ($ret) { - $cid_str = sprintf("%-4d", $cid); - drush_print('Comment: '. $cid_str . "\tTitle: " . $comment->title); - drush_print("\t\tURL: " . drupal_get_path_alias('node/'.$comment->nid) . '#comment-' . $cid ); - drush_print("\t\tMatch: " . $matches[0]); - drush_print(); - } - } - } - - if (in_array('block', $list)) { - drush_print('TODO: grepping blocks is not supported yet'); - } - -}