Sha256: 04f5f253742cfd7cccb89c7a3cdd7e26c5a0f342094eb9ec3b71f1fc73d59acf

Contents?: true

Size: 1.65 KB

Versions: 1

Compression:

Stored size: 1.65 KB

Contents

#!/usr/bin/env ruby

require 'scout'
require 'scout/knowledge_base'

$0 = "scout #{$previous_commands.any? ? $previous_commands*" " + " " : "" }#{ File.basename(__FILE__) }" if $previous_commands

options = SOPT.setup <<EOF

Traverse databases

$ #{$0} [<options>] <traversal>

-h--help Print this help
-kb--knowledge_base* Knowlege base name (or :default)
-p--paths Only list paths
-e--entities Only list entities
-l--list* List entities matching capture
-ln--list_name* Save list of matches with a name
EOF
if options[:help]
  if defined? scout_usage
    scout_usage 
  else
    puts SOPT.doc
  end
  exit 0
end

traversal = ARGV.first

raise MissingParameterException, :traversal if traversal.nil?

knowledge_base = KnowledgeBase.load options[:knowledge_base] || :default

only_paths, only_entities, list, list_name = IndiferentHash.process_options options, :paths, :entities, :list, :list_name

rules = traversal.split(/,\s*/)

knowledge_base.define_entity_modules

entities, paths = knowledge_base.traverse(rules, only_entities || list)

if list
  entity_list = entities["?" + list] || []
  puts entity_list * "\n"
  knowledge_base.save_list list_name, entity_list if list_name
else
  paths = nil if only_entities && ! only_paths
  entities = nil if only_paths && ! only_entities

  if entities
    entities.each do |type,list|
      puts Log.color(:magenta, type[1..-1] + ": ") + Log.fingerprint(list * ", ")
    end
  end

  if paths
    paths.each do |path_list|
      path_list.each do |match|
        puts Log.color :magenta, (match.reverse ? match.invert : match)
        puts IndiferentHash.setup(match.info).prety_print if match.info && match.info.any?
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
scout-gear-10.7.3 scout_commands/kb/traverse