Sha256: 2f518063756cd0658bac0782f63c030d95c097a7ad2a86dbb0a20dfe72ce5655

Contents?: true

Size: 1.03 KB

Versions: 2

Compression:

Stored size: 1.03 KB

Contents

# frozen_string_literal: true

require "thor"
require "json"

module DoHClient
  class CLI < Thor
    class_option :resolver, type: :string, desc: "a resolver to use ('google' or 'cloudflare', default: google)"

    desc "resolve [NAME]", "resolve a given name"
    method_option :type, type: :string, default: "A"
    method_option :cd, type: :boolean
    method_option :do, type: :boolean
    method_option :edns_client_subnet, type: :string
    method_option :random_padding, type: :string
    def resolve(name)
      hash = resolver.resolve(name, options)
      puts hash.to_json
    end

    no_commands do
      def resolver
        case options[:resolver]
        when "google"
          DoHClient::Client::Google
        when "cloudflare"
          DoHClient::Client::Cloudflare
        else
          DoHClient::Client::Google
        end
      end

      def with_error_handling
        yield
      rescue ResponseError => e
        puts "Warning: #{e}"
      rescue ArgumentError => _
        puts "Warning: #{e}"
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
doh_client-0.1.1 lib/doh_client/cli.rb
doh_client-0.1.0 lib/doh_client/cli.rb