13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
from bzrlib.commands import Command, register_command
20
from bzrlib.commands import Command, register_command, display_command
21
from bzrlib.option import (
25
from bzrlib.lazy_import import lazy_import
26
lazy_import(globals(), """
23
34
version_info = (0, 1)
25
36
class cmd_grep(Command):
28
takes_args = ['file*']
30
def run(self, file_list):
31
print "Hello World!!!"
37
"""Print lines matching PATTERN for specified files.
40
takes_args = ['pattern', 'path*']
43
Option('line-number', short_name='n',
44
help='prefix each line of output with 1-based line number.'),
45
Option('null', short_name='z',
46
help='Write an ascii NUL (\\0) separator '
47
'between files rather than a newline.'),
48
Option('ignore-case', short_name='i',
49
help='ignore case distinctions while matching.'),
50
Option('recursive', short_name='R',
51
help='Recurse into subdirectories.'),
53
help='Search for pattern starting from the root of the branch.'),
58
def run(self, verbose=False, line_number=False, null=False,
59
ignore_case=False, recursive=False, from_root=False,
60
path_list=None, pattern=None):
65
raise errors.BzrCommandError('cannot specify both --from-root and PATH.')
67
print 'pattern:', pattern
68
print 'path_list:', path_list
69
print 'ignore-case:', ignore_case
70
print 'line-number:', line_number
72
print 'recursive:', recursive
73
print 'from-root:', from_root
76
tree, branch, relpath = bzrdir.BzrDir.open_containing_tree_or_branch('.')
79
self.add_cleanup(tree.unlock)
80
for path in path_list:
81
for fp, fc, fkind, fid, entry in tree.list_files(include_root=False,
82
from_dir=relpath, recursive=recursive):
88
if fc == 'V' and fkind == 'file':
92
def file_grep(self, path):
93
print path + ': grepping ...'
34
95
register_command(cmd_grep)