sup

A curses threads-with-tags style email client

sup.git

git clone https://supmua.dev/git/sup/
commit ea76deb89fea2f0a7ea66425ba5b7177a37ea5ad
parent 17d95eec297c83774b820b7cb811534ad0d32790
Author: Gaute Hope <eg@gaute.vetsj.com>
Date:   Tue, 29 Sep 2015 14:35:52 +0200

Merge #393 into develop

Diffstat:
M bin/sup | 5 +++--
M lib/sup/hook.rb | 16 ++++++++--------
2 files changed, 11 insertions(+), 10 deletions(-)
diff --git a/bin/sup b/bin/sup
@@ -39,7 +39,8 @@ Usage:
 
 Options are:
 EOS
-  opt :list_hooks, "List all hooks and descriptions, and quit."
+  opt :list_hooks, "List all hooks and descriptions, and quit. Use --hooks-matching to filter."
+  opt :hooks_matching, "If given, list all hooks and descriptions matching the given pattern. Needs the --list-hooks option", short: "m", default: ""
   opt :no_threads, "Turn off threading. Helps with debugging. (Necessarily disables background polling for new messages.)"
   opt :no_initial_poll, "Don't poll for new messages when starting."
   opt :search, "Search for this query upon startup", :type => String
@@ -65,7 +66,7 @@ EOS
 
 if $opts[:list_hooks]
   Redwood.start
-  Redwood::HookManager.print_hooks
+  Redwood::HookManager.print_hooks $opts[:hooks_matching]
   exit
 end
 
diff --git a/lib/sup/hook.rb b/lib/sup/hook.rb
@@ -109,20 +109,20 @@ class HookManager
     @descs[name] = desc
   end
 
-  def print_hooks f=$stdout
-puts <<EOS
-Have #{HookManager.descs.size} registered hooks:
-
-EOS
-
-    HookManager.descs.sort.each do |name, desc|
-      f.puts <<EOS
+  def print_hooks pattern="", f=$stdout
+    matching_hooks = HookManager.descs.sort.keep_if {|name, desc| pattern.empty? or name.match(pattern)}.map do |name, desc|
+      <<EOS
 #{name}
 #{"-" * name.length}
 File: #{fn_for name}
 #{desc}
 EOS
     end
+
+    showing_str = matching_hooks.size == HookManager.descs.size ? "" : " (showing #{matching_hooks.size})"
+    f.puts "Have #{HookManager.descs.size} registered hooks#{showing_str}:"
+    f.puts
+    matching_hooks.each { |text| f.puts text }
   end
 
   def enabled? name; !hook_for(name).nil? end