Class: Sonar::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/sonar/cli/cli.rb

Instance Method Summary collapse

Constructor Details

#initializeCLI

Returns a new instance of CLI.



15
16
17
18
19
# File 'lib/sonar/cli/cli.rb', line 15

def initialize(*)
  @config = Sonar::RCFile.instance.load_file
  @client = Sonar::Client.new(email: @config["email"], access_token: @config["access_token"], api_url: @config["api_url"])
  super
end

Instance Method Details

#configObject



62
63
64
65
# File 'lib/sonar/cli/cli.rb', line 62

def config
  # TODO: add a way to set config
  puts "Your config file is located at #{RCFile.instance.path}"
end

#profileObject



22
23
24
# File 'lib/sonar/cli/cli.rb', line 22

def profile
  ap @config
end

#search(type, term) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/sonar/cli/cli.rb', line 34

def search(type, term)
  types = [type]

  if type == 'all'
    if term =~ IS_IP
      types = ip_search_type_names
    else
      types = domain_search_type_names
    end
  end

  types.each do |type|
    @query = {}
    @query[type.to_sym] = term
    @query[:limit] = options['record_limit']
    @query[:exact] = options['exact']
    resp = @client.search(@query)
    handle_search_response(resp)
  end
end

#typesObject



56
57
58
59
# File 'lib/sonar/cli/cli.rb', line 56

def types
  tp.set :io, $stdout
  tp QUERY_TYPES, :name, { description: { width: 100 } }, :input
end

#usageObject



27
28
29
# File 'lib/sonar/cli/cli.rb', line 27

def usage
  ap @client.usage
end