commit 8fd8b91e260b5b72b7f6c9f6f0dc7517a4cb10d6
parent 13e0035d02bb88e33b8093e7b346d2520deb59c7
Author: Matthieu Rakotojaona <matthieu.rakotojaona@gmail.com>
Date: Thu, 12 Feb 2015 23:57:22 +0100
Filter list-hooks with pattern given with -m option
Diffstat:
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