Class: BitClust::Subcommands::ChecklinkCommand

Inherits:
BitClust::Subcommand show all
Defined in:
lib/bitclust/subcommands/checklink_command.rb

Instance Method Summary collapse

Methods inherited from BitClust::Subcommand

#align_progress_bar_title, #error, #help, #needs_database?, #option_error, #parse, #srcdir_root

Constructor Details

#initializeChecklinkCommand

Returns a new instance of ChecklinkCommand.



22
23
24
25
26
27
28
29
# File 'lib/bitclust/subcommands/checklink_command.rb', line 22

def initialize
  super
  @capi_prefix = nil
  @parser.banner = "Usage: #{File.basename($0, '.*')} --database=PATH checklink [options]"
  @parser.on('--capi-database=PATH', 'C API (function) database for [[f:]] refs.') {|path|
    @capi_prefix = path
  }
end

Instance Method Details

#exec(argv, options) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/bitclust/subcommands/checklink_command.rb', line 31

def exec(argv, options)
  super
  db = @db
  unless db.is_a?(MethodDatabase)
    error 'checklink is for method databases (do not use --capi; pass --capi-database instead)'
  end
  capi_prefix = @capi_prefix
  fdb = capi_prefix ? BitClust::FunctionDatabase.new(capi_prefix) : nil
  checker = LinkChecker.new(db, function_database: fdb)
  checker.check_all
  # 同一エントリ内の同一参照の繰り返しは1行にまとめる
  checker.findings.map {|f| "#{f.location}: [[#{f.ref}]] #{f.message}" }.uniq.each do |line|
    puts line
  end
  if fdb.nil? && checker.skipped_function_refs > 0
    puts "note: #{checker.skipped_function_refs} [[f:]] refs skipped (no --capi-database)"
  end
  version = @db.properties['version']
  puts "#{checker.broken_count} broken link(s) in #{version ? "db (version #{version})" : 'db'}"
  exit 1 unless checker.broken_count.zero?
end