Sha256: 8c4c9dcbacf0544a91531c3917517d391e39e6919118833c6d2e87202b864b46

Contents?: true

Size: 1.31 KB

Versions: 2

Compression:

Stored size: 1.31 KB

Contents

# frozen_string_literal: true

require "thor"

require "json"

module Tansaku
  class CLI < Thor
    desc "crawl URL", "Crawl a given URL"
    method_option :additional_list, desc: "Path to the file which includes additional paths to crawl"
    method_option :headers, type: :hash, default: {}, desc: "HTTP headers to use"
    method_option :method, type: :string, default: "HEAD", desc: "HTTP method to use"
    method_option :body, type: :string, required: false, default: nil, desc: "HTTP request body to use"
    method_option :timeout, type: :numeric, required: false, default: nil, desc: "Timeout in seconds"
    method_option :max_concurrent_requests, type: :numeric, desc: "Max number of concurrent requests to use"
    method_option :ignore_certificate_errors, type: :boolean, default: false, desc: "Whether to ignore certificate errors or not"
    method_option :type, desc: "Type of a list to crawl (admin, backup, database, etc, log or all)", default: "all"
    def crawl(url)
      params = options.compact.transform_keys(&:to_sym)
      begin
        crawler = Crawler.new(url, **params)
        results = crawler.crawl
        puts results.to_json
      rescue ArgumentError => e
        puts e
      end
    end

    default_command :crawl

    class << self
      def exit_on_failure?
        true
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
tansaku-1.4.0 lib/tansaku/cli.rb
tansaku-1.3.0 lib/tansaku/cli.rb