Class: MysqlInspector::CLI::GrepCommand

Inherits:
Command
  • Object
show all
Includes:
Formatting
Defined in:
lib/mysql_inspector/cli.rb

Instance Attribute Summary

Attributes inherited from Command

#config, #status, #stderr, #stdout

Instance Method Summary collapse

Methods included from Formatting

#format_items

Methods inherited from Command

#get_dump, #initialize, #ivar, #parse!, #run!

Methods included from Helper

#abort, #exit, #puts, #usage

Constructor Details

This class inherits a constructor from MysqlInspector::CLI::Command

Instance Method Details

#parse(argv) ⇒ Object



200
201
202
203
# File 'lib/mysql_inspector/cli.rb', line 200

def parse(argv)
  @version = CURRENT
  @matchers = *argv.map { |a| Regexp.new(a) }
end

#runObject



205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
# File 'lib/mysql_inspector/cli.rb', line 205

def run
  dump = get_dump(@version)

  grep = Grep.new(dump, @matchers)
  grep.execute

  puts "grep #{@matchers.map { |m| m.inspect } * " AND "}"

  puts if grep.any_matches?

  grep.each_table { |table, subset|
    puts table.table_name
    format_items("COL", subset.columns)
    format_items("IDX", subset.indices)
    format_items("CST", subset.constraints)
    puts
  }
end