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


13
14
15
16
17
# File 'lib/sonar/cli/cli.rb', line 13

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


46
47
48
49
# File 'lib/sonar/cli/cli.rb', line 46

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

#profileObject


20
21
22
# File 'lib/sonar/cli/cli.rb', line 20

def profile
  ap @config
end

#search(type, term) ⇒ Object


31
32
33
34
35
36
37
38
# File 'lib/sonar/cli/cli.rb', line 31

def search(type, term)
  @query = {}
  @query[type.to_sym] = term
  @query[:limit] = options['record_limit']
  @client.search(@query).each do |data|
    print_json(cleanup_data(data), options['format'])
  end
end

#typesObject


41
42
43
# File 'lib/sonar/cli/cli.rb', line 41

def types
  ap Search::QUERY_TYPES_MAP
end

#usageObject


25
26
27
# File 'lib/sonar/cli/cli.rb', line 25

def usage
  ap @client.usage
end