Class: Ronin::Wordlists::CLI::Commands::Search Private

Inherits:
Ronin::Wordlists::CLI::Command show all
Defined in:
lib/ronin/wordlists/cli/commands/search.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Lists wordlists available for download or installation.

Usage

ronin-wordlists search [options]

Options

-c, --category NAME              Filters wordlists by a specific category
-h, --help                       Print help information

Arguments: [KEYWORD] Optional search keyword

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**kwargs) ⇒ Search

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initializes the ronin-wordlists search command.

Parameters:

  • kwargs (Hash{Symbol => Object})

    Additional keyword arguments for the command.



76
77
78
79
80
# File 'lib/ronin/wordlists/cli/commands/search.rb', line 76

def initialize(**kwargs)
  super(**kwargs)

  @categories = Set.new
end

Instance Attribute Details

#categoriesSet<String> (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Wordlist categories to filter by.

Returns:

  • (Set<String>)


68
69
70
# File 'lib/ronin/wordlists/cli/commands/search.rb', line 68

def categories
  @categories
end

Instance Method Details

#print_entry(entry) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Prints an entry from the wordlist index file.

Parameters:



132
133
134
135
136
137
138
139
# File 'lib/ronin/wordlists/cli/commands/search.rb', line 132

def print_entry(entry)
  puts "[ #{entry.name} ]"
  puts
  puts "  * URL: #{entry.url}"
  puts "  * Categories: #{entry.categories.join(', ')}"
  puts "  * Summary: #{entry.summary}"
  puts
end

#run(keyword = nil) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Runs the ronin-wordlists search command.

Parameters:

  • keyword (String, nil) (defaults to: nil)

    The optional search keyword.



88
89
90
91
92
# File 'lib/ronin/wordlists/cli/commands/search.rb', line 88

def run(keyword=nil)
  search(keyword, categories: @categories).each do |entry|
    print_entry(entry)
  end
end

#search(keyword = nil, categories: Set.new) ⇒ Enumerator::Lazy

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Searches for matching entries in the wordlist index file.

Parameters:

  • keyword (String, nil) (defaults to: nil)

    The optional search keyword.

  • categories (Set<String>, nil) (defaults to: Set.new)

    The optional set of categories to filter by.

Returns:

  • (Enumerator::Lazy)

    The filtered wordlist index entries.



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/ronin/wordlists/cli/commands/search.rb', line 106

def search(keyword=nil, categories: Set.new)
  entries = WordlistIndex.load.lazy

  unless categories.empty?
    entries = entries.filter do |entry|
      categories.subset?(entry.categories)
    end
  end

  if keyword
    entries = entries.filter do |entry|
      entry.name.include?(keyword)      ||
        entry.summary.include?(keyword) ||
        entry.categories.include?(keyword)
    end
  end

  return entries
end