Module: BrowserCrawler::Options

Defined in:
lib/browser_crawler/options.rb

Class Method Summary collapse

Class Method Details

.default_optionsObject



7
8
9
10
11
12
13
14
# File 'lib/browser_crawler/options.rb', line 7

def default_options
  {
    report_folder: 'tmp',
    report_format: 'yaml',
    window_width: 1024,
    window_height: 768
  }
end

.parse_argsObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/browser_crawler/options.rb', line 16

def parse_args
  options = {}
  p = OptionParser.new do |opts|
    opts.on_tail

    opts.banner = 'Site crawler. Usage example: crawl http://localhost:3000'

    opts.on('-U', '[--url] URL', 'Crawls the site starting from the url specified. E.g. http://localhost:3000/welcome.') do |v|
      options[:url] = v
    end

    opts.on('-u', '--user USERNAME', 'The authentication user name (optional).') do |v|
      options[:username] = v
    end

    opts.on('-p', '--password PASSWORD', 'The authentication password (optional).') do |v|
      options[:password] = v
    end

    opts.on('-n', '--max_pages NUM', 'The maximum number of pages to visit.') do |v|
      options[:max_pages] = v.to_i
    end

    opts.on('-w', '--window_size WxH', 'Browser window size. Default 1024x768') do |v|
      options[:window_width], options[:window_height] = v.split('x')
    end

    opts.on('-r', '--report FOLDER', 'The folder path to save report to. '\
                                     'Default: tmp') do |v|
      options[:report_folder] = v
    end

    opts.on('-f', '--report_format TYPE', 'The report type to save result  '\
                                     'Default: yaml') do |v|
      options[:report_format] = v
    end

    opts.on('-s', '--screenshots_path PATH',
            'If specified along with the url, screenshots are captured visiting each page.'\
            ' Otherwise used to generate a screenshots index based on files caprured previously. ') do |v|
      options[:screenshots_path] = v
    end

    opts.on('-t', '--template FILENAME',
            'Specify the template used for indexing.'\
            '  Default: followups/templates/index.html.erb') do |v|
      options[:index_template] = v
    end

    opts.on('-c', '--wraith_config FILENAME',
            'Update config "paths" section with the pages extracted.') do |v|
      options[:wraith_config] = v
    end

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

  options[:url] = ARGV.pop unless ARGV.empty?

  if options.empty?
    puts p
    exit
  end

  default_options.merge(options)
end