commit:     149ce341820a66010e8592975d86e5d6dd0c6b7e
Author:     Robin H. Johnson <robbat2 <AT> gentoo <DOT> org>
AuthorDate: Tue Feb 24 01:47:30 2015 +0000
Commit:     Robin H. Johnson <robbat2 <AT> gentoo <DOT> org>
CommitDate: Tue Feb 24 01:49:07 2015 +0000
URL:        http://sources.gentoo.org/gitweb/?p=proj/ag.git;a=commit;h=149ce341

Expose delete index.

Signed-off-by: Robin H. Johnson <robbat2 <AT> gentoo.org>

---
 ag             | 23 +++++++++++++++++++----
 lib/storage.rb | 11 +++++++++--
 2 files changed, 28 insertions(+), 6 deletions(-)

diff --git a/ag b/ag
index c5056ff..4636675 100755
--- a/ag
+++ b/ag
@@ -27,7 +27,7 @@ $options.readonly = false
 $options.jobs = false
 
 op = OptionParser.new do |opts|
-  opts.banner = "Usage: ag 
<<--index-full|--index-new|--delete|--reindex|--info> <--list listname>> 
<[--file|--msgid|--hash] <maildir/file/hash/messageid>> [options]"
+  opts.banner = "Usage: ag 
<<--index-full|--index-new|--delete-msg|--delete-index|--reindex|--info> 
<--list listname>> <[--file|--msgid|--hash] <maildir/file/hash/messageid>> 
[options]"
 
   opts.on('--index-full', 'Read the full past archive from the .cur Maildir') 
do
     abort 'Can only select one action' if $options.action != nil
@@ -41,10 +41,16 @@ op = OptionParser.new do |opts|
     $options.action = :do_incremental
   end
 
-  opts.on('--delete', 'Delete message. Needs --file, --msgid, or --hash') do
+  opts.on('--delete-msg', 'Delete message. Needs --file, --msgid, or --hash') 
do
     abort 'Can only select one action' if $options.action != nil
 
-    $options.action = :do_delete
+    $options.action = :do_delete_msg
+  end
+  
+  opts.on('--delete-Index', 'Delete index. Needs --list') do
+    abort 'Can only select one action' if $options.action != nil
+
+    $options.action = :do_index
   end
 
   opts.on('--info', 'Display message details. Needs --file, --msgid, or 
--hash') do
@@ -156,7 +162,7 @@ def do_incremental
   Ag::Threading.calc($options.name) unless $options.no_threading
 end
 
-def do_delete
+def do_delete_msg
   id = Ag::Utils.resolve_id
 
   begin
@@ -166,6 +172,15 @@ def do_delete
   end
 end
 
+def do_delete_index
+  begin
+    Ag::Storage.delete_index($options.name)
+  rescue Elasticsearch::Transport::Transport::Errors::NotFound => e
+  rescue => e
+    $stderr.puts "Cannot delete index: #{e}"
+  end
+end
+
 def do_reindex
   abort 'Come back later.'
 end

diff --git a/lib/storage.rb b/lib/storage.rb
index 5b360f5..656a6bf 100644
--- a/lib/storage.rb
+++ b/lib/storage.rb
@@ -3,9 +3,16 @@ require 'date'
 
 module Ag::Storage
   module_function
+
+  # Throws Elasticsearch::Transport::Transport::Errors::NotFound
+  # if the list does not exist
+  def delete_index(list)
+      $es.indices.delete index: 'ml-' + list
+  end
+
   def create_index(list)
     begin
-      $es.indices.delete index: 'ml-' + list
+      delete_index(ist)
     rescue Elasticsearch::Transport::Transport::Errors::NotFound => e
       $stderr.puts "Index did not exist yet. Creating." if $options.debug
     end
@@ -267,4 +274,4 @@ module Ag::Storage
     return nil if result['hits']['total'] == 0
     result['hits']['hits'].first
   end
-end
\ No newline at end of file
+end

Reply via email to