Class: Sonar::CLI
- Inherits:
-
Thor
- Object
- Thor
- Sonar::CLI
- Defined in:
- lib/sonar/cli/cli.rb
Instance Method Summary collapse
- #config ⇒ Object
-
#initialize ⇒ CLI
constructor
A new instance of CLI.
- #profile ⇒ Object
- #search(type, term) ⇒ Object
- #types ⇒ Object
- #usage ⇒ Object
Constructor Details
#initialize ⇒ CLI
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
#config ⇒ Object
55 56 57 58 |
# File 'lib/sonar/cli/cli.rb', line 55 def config # TODO: add a way to set config puts "Your config file is located at #{RCFile.instance.path}" end |
#profile ⇒ Object
20 21 22 |
# File 'lib/sonar/cli/cli.rb', line 20 def profile ap @config end |
#search(type, term) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/sonar/cli/cli.rb', line 33 def search(type, term) @query = {} @query[type.to_sym] = term @query[:limit] = ['record_limit'] @query[:exact] = ['exact'] resp = @client.search(@query) if resp.is_a?(Sonar::Request::RequestIterator) resp.each do |data| print_json(cleanup_data(data), ['format']) end else print_json(cleanup_data(resp), ['format']) end end |
#types ⇒ Object
50 51 52 |
# File 'lib/sonar/cli/cli.rb', line 50 def types ap Search::QUERY_TYPES_MAP end |
#usage ⇒ Object
25 26 27 |
# File 'lib/sonar/cli/cli.rb', line 25 def usage ap @client.usage end |