Class: MGit::GrepCommand

Inherits:
Command show all
Defined in:
lib/mgit/commands/grep.rb

Instance Method Summary collapse

Methods inherited from Command

create, #help, instance_each, list, register_alias, register_command

Instance Method Details

#descriptionObject



20
21
22
# File 'lib/mgit/commands/grep.rb', line 20

def description
  'grep for a pattern in each repository'
end

#execute(args) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
# File 'lib/mgit/commands/grep.rb', line 3

def execute(args)
  raise TooFewArgumentsError.new(self) if args.size == 0
  raise TooManyArgumentsError.new(self) if args.size > 1

  ptrn = args[0]

  Registry.chdir_each do |repo|
    puts "Looking for pattern '#{ptrn}' in repository #{repo.name}...".yellow
    puts `git grep #{ptrn}`
    puts
  end
end

#usageObject



16
17
18
# File 'lib/mgit/commands/grep.rb', line 16

def usage
  'grep <pattern>'
end