Sha256: b4732b8d9f703fd778b70d9eec3257c9518b2c87ce8619f8d43f8fdcfc0316b1
Contents?: true
Size: 1.5 KB
Versions: 1
Compression:
Stored size: 1.5 KB
Contents
require 'json' require 'fileutils' require 'open3' require 'arli' require 'arli/commands/base' require 'arli/errors' require 'arduino/library' require 'awesome_print' module Arli module Commands class Search < Base require 'arduino/library/include' attr_accessor :search_string, :search_opts, :limit, :database def initialize(options) super(options) self.search_string = options[:argv].first puts "using search string [#{search_string}]" if search_string && Arli.debug? self.limit = options[:limit] || 100 raise Arli::Errors::InvalidSyntaxError, 'Please provide search string after the "search" command' \ unless search_string begin self.search_opts = eval("{ #{search_string} }") rescue => e raise Arli::Errors::InvalidSyntaxError, "Search string '#{search_string}' is invalid.\n" + e.message.red end unless search_opts.is_a?(::Hash) && search_opts.size > 0 raise Arli::Errors::InvalidSyntaxError, "Search string '#{search_string}' did not eval to Hash.\n" end self.database = options[:database] ? db_from(option[:database]) : db_default search_opts.merge!(limit: limit) if limit && limit > 0 end def run ap search(database, **search_opts).map(&:to_hash) rescue Exception => e error e puts e.backtrace.join("\n") if ENV['DEBUG'] end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
arli-0.5.1 | lib/arli/commands/search.rb |