commit: 3aeff5af03460eea82b31c493c6bfa635f80cf72 Author: Alex Legler <alex <AT> a3li <DOT> li> AuthorDate: Mon Feb 23 00:05:05 2015 +0000 Commit: Alex Legler <a3li <AT> gentoo <DOT> org> CommitDate: Mon Feb 23 00:05:05 2015 +0000 URL: http://sources.gentoo.org/gitweb/?p=proj/ag.git;a=commit;h=3aeff5af
Implement --info --- ag | 23 ++++++++++++++++++++++- lib/storage.rb | 18 ++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/ag b/ag index be04609..29ee0f2 100755 --- a/ag +++ b/ag @@ -42,6 +42,12 @@ op = OptionParser.new do |opts| $options.action = :do_delete end + opts.on('--info', 'Display message details. Needs --file, --msgid, or --hash') do + abort 'Can only select one action' if $options.action != nil + + $options.action = :do_info + end + opts.on('--reindex', 'Reindex message. Needs --file') do abort 'Can only select one action' if $options.action != nil @@ -144,7 +150,22 @@ def do_reindex end def do_info - abort 'Come back later.' + id = Ag::Utils.resolve_id + + begin + message = Ag::Storage.get($options.name, id) + + raise 'No such message' unless message + + require 'pp' + str = "Message #{id}" + $stderr.puts str + $stderr.puts '-' * str.length + + pp message['_source'] + rescue => e + $stderr.puts "Cannot display message: #{e}" + end end ############################################################################### diff --git a/lib/storage.rb b/lib/storage.rb index 37083fa..b4a518e 100644 --- a/lib/storage.rb +++ b/lib/storage.rb @@ -220,4 +220,22 @@ module Ag::Storage result['hits']['total'] end + def get(list, id) + result = $es.search( + index: 'ml-' + list, + size: 1, + body: { + query: { + filtered: { + filter: { + term: { _id: id } + } + } + } + } + ) + + return nil if result['hits']['total'] == 0 + result['hits']['hits'].first + end end \ No newline at end of file