class Snapcrawl::CLI

Public Instance Methods

call(args = []) click to toggle source
# File lib/snapcrawl/cli.rb, line 11
def call(args = [])
  begin
    execute Docopt::docopt(docopt, version: VERSION, argv: args)
  rescue Docopt::Exit => e
    puts e.message
  end
end

Private Instance Methods

apply_tweaks(tweaks) click to toggle source
# File lib/snapcrawl/cli.rb, line 47
def apply_tweaks(tweaks)
  tweaks.each do |key, value|
    Config.settings[key] = value
    $logger.level = value if key == 'log_level'
  end
end
docopt() click to toggle source
# File lib/snapcrawl/cli.rb, line 39
def docopt
  @doc ||= File.read docopt_path
end
docopt_path() click to toggle source
# File lib/snapcrawl/cli.rb, line 43
def docopt_path
  File.expand_path "templates/docopt.txt", __dir__
end
execute(args) click to toggle source
# File lib/snapcrawl/cli.rb, line 21
def execute(args)
  config_file = args['--config']
  Config.load config_file if config_file

  tweaks = args['SETTINGS'].pair_split
  apply_tweaks tweaks if tweaks

  Dependencies.verify
  
  $logger.debug 'initializing cli'
  FileUtils.mkdir_p Config.snaps_dir

  url = args['URL'].protocolize
  crawler = Crawler.new url

  crawler.crawl
end