Sha256: 22b97c8768713d4d3510c791e891ff59588e9cade20bf63719db03c52afc3113

Contents?: true

Size: 1.82 KB

Versions: 12

Compression:

Stored size: 1.82 KB

Contents

#!/usr/bin/env ruby
# frozen_string_literal: true

require 'optparse'
require 'ostruct'
require 'recog'
require 'recog/matcher_factory'

options = OpenStruct.new(color: false, detail: false, json_format: false, fail_fast: false, multi_match: false)

option_parser = OptionParser.new do |opts|
  opts.banner = "Usage: #{$PROGRAM_NAME} [options] XML_FINGERPRINT_FILE [BANNERS_FILE]"
  opts.separator 'Identifies the matches and misses between the fingerprints and the banners file or STDIN'
  opts.separator ''
  opts.separator 'Options'

  opts.on('-f', '--format FORMATTER', %i[summary detail json],
          'Choose a formatter.',
          '  [s]ummary (default - failure/match msgs)',
          '  [d]etail  (msgs with total counts)',
          '  [j]son    (JSON failure/match msgs)') do |format|
    case format
    when :summary
      options.detail = false
      options.json_format = false
    when :detail
      options.detail = true
    when :json
      options.json_format = true
    end
  end

  opts.on('--fail-fast [NUM]',
          'Stop after number of failures (default: 10).') do |num|
    options.fail_fast = true
    options.stop_after = num.to_i == 0 ? 10 : num.to_i
  end

  opts.on('-c', '--color', 'Enable color in the output.') do
    options.color = true
  end

  opts.on('--[no-]multi-match', 'Enable or disable multiple matches (defaults to disabled)') do |o|
    options.multi_match = o
  end

  opts.on('-h', '--help', 'Show this message.') do
    puts opts
    exit
  end
end

begin
  option_parser.parse!(ARGV)
rescue OptionParser::ParseError => e
  puts e.message
  puts option_parser
  exit(1)
end

if ARGV.count < 1 || ARGV.count > 2
  puts option_parser
  exit(1)
end

ndb = Recog::DB.new(ARGV.shift)
options.fingerprints = ndb.fingerprints
matcher = Recog::MatcherFactory.build(options)
matcher.match_banners(ARGV.shift || '-')

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
recog-3.1.13 recog/bin/recog_match
recog-3.1.12 recog/bin/recog_match
recog-3.1.11 recog/bin/recog_match
recog-3.1.10 recog/bin/recog_match
recog-3.1.9 recog/bin/recog_match
recog-3.1.8 recog/bin/recog_match
recog-3.1.7 recog/bin/recog_match
recog-3.1.6 recog/bin/recog_match
recog-3.1.5 recog/bin/recog_match
recog-3.1.4 recog/bin/recog_match
recog-3.1.3 recog/bin/recog_match
recog-3.1.2 recog/bin/recog_match