lib/lita/handlers/locker_misc.rb in lita-locker-1.0.5 vs lib/lita/handlers/locker_misc.rb in lita-locker-1.0.6
- old
+ new
@@ -8,11 +8,11 @@
include ::Locker::Misc
include ::Locker::Regex
include ::Locker::Resource
route(
- /^locker\sstatus\s#{LABEL_REGEX}$/,
+ /^locker\sstatus\s#{LABEL_WILDCARD_REGEX}$/,
:status,
command: true,
help: { t('help.status.syntax') => t('help.status.desc') }
)
@@ -46,12 +46,21 @@
end
end
def status(response)
name = response.match_data['label']
- return response.reply(status_label(name)) if Label.exists?(name)
- return response.reply(status_resource(name)) if Resource.exists?(name)
- response.reply(failed(t('subject.does_not_exist', name: name)))
+ unless name =~ /\*/
+ # Literal query
+ return response.reply(status_label(name)) if Label.exists?(name)
+ return response.reply(status_resource(name)) if Resource.exists?(name)
+ end
+ # Wildcard query
+ matcher = Regexp.new(name.gsub(/\*/, '.*'))
+ labels = Label.list.select { |label| label =~ matcher }
+ return response.reply(failed(t('subject.does_not_exist', name: name))) if labels.empty?
+ labels.each do |n|
+ response.reply(status_label(n))
+ end
end
def dequeue(response)
name = response.match_data['label']
return response.reply(t('subject.does_not_exist', name: name)) unless Label.exists?(name)