Class: RooTools::RooGrepRunner

Inherits:
UserChoices::Command
  • Object
show all
Includes:
UserChoices
Defined in:
lib/roo-tools.rb

Instance Method Summary collapse

Constructor Details

#initializeRooGrepRunner

Returns a new instance of RooGrepRunner.



10
11
12
13
14
15
# File 'lib/roo-tools.rb', line 10

def initialize
 @seen = {}
 @matches = 0
 @matching_files = 0
 super
end

Instance Method Details

#add_choices(builder) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/roo-tools.rb', line 21

def add_choices(builder)
  builder.add_choice(:list_only, :type=>:boolean, :default=>false) do | command_line |
    command_line.uses_option("-l", "--list-only", "List matching files only")
  end
  builder.add_choice(:case_insensitive, :type=>:boolean, :default=>false) do | command_line |
    command_line.uses_option("-i", "--case-insensitive", "Case insensitive search")
  end
  builder.add_choice(:exact_match, :type=>:boolean, :default=>false) do | command_line |
    command_line.uses_option("-e", "--exact-match", "Force exact match on cell contents")
  end
  builder.add_choice(:font, :type=>['bold','italic','underline','normal','ignore'], :default=>'ignore') do | command_line |
    command_line.uses_option("-f", "--font STYLE", "Filter results by cell font style")
  end
  builder.add_choice(:tabs, :type=>:boolean, :default=>true) do | command_line |
    command_line.uses_switch("--tabs", "Show/hide tabs in results")
  end
  builder.add_choice(:cells, :type=>:boolean, :default=>true) do | command_line |
    command_line.uses_switch("--cells", "Show/hide cells in results")
  end
  builder.add_choice(:recurse, :type=>:boolean, :default=>false) do | command_line |
    command_line.uses_switch("-r", "--recurse", "Search in subdirectories")
  end
  builder.add_choice(:files) { |command_line |
    command_line.uses_arglist
  }
end

#add_sources(builder) ⇒ Object



17
18
19
# File 'lib/roo-tools.rb', line 17

def add_sources(builder)
  builder.add_source(CommandLineSource, :usage, "Usage: oogrep.rb [options] searchstring targets")
end

#executeObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/roo-tools.rb', line 48

def execute
  if @user_choices[:help]
    puts @user_choices[:usage]
    exit 0
  end
  @user_choices[:searchstring] = @user_choices[:files].shift
  puts 
  start_interrupt_handler
  oogrep = Grep.new(@user_choices)
  oogrep.process_files
  unless @user_choices[:list_only]
    puts "#{oogrep.matches} matches in #{oogrep.matching_files} file(s)"
  end
  return 0
end