Merge lp:~max-rabkin/ibid/helpful-help into lp:~ibid-core/ibid/old-trunk-1.6

Proposed by Max Rabkin
Status: Merged
Approved by: Jonathan Hitchcock
Approved revision: not available
Merged at revision: 831
Proposed branch: lp:~max-rabkin/ibid/helpful-help
Merge into: lp:~ibid-core/ibid/old-trunk-1.6
Diff against target: 55 lines (+34/-1)
1 file modified
ibid/plugins/help.py (+34/-1)
To merge this branch: bzr merge lp:~max-rabkin/ibid/helpful-help
Reviewer Review Type Date Requested Status
Jonathan Hitchcock Approve
Michael Gorven Approve
Stefano Rivera Approve
Review via email: mp+16934@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Max Rabkin (max-rabkin) wrote :

Suggestions for alternative syntaxes if you have them, please.

Revision history for this message
Stefano Rivera (stefanor) wrote :

Can't complain

review: Approve
Revision history for this message
Michael Gorven (mgorven) wrote :

Nice
 review approve

review: Approve
Revision history for this message
Jonathan Hitchcock (vhata) wrote :

This is cool, although I think it's just a first step towards properly helpful help.

Let's get this in, and then think about how to improve it more?

Approve.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'ibid/plugins/help.py'
--- ibid/plugins/help.py 2009-12-30 15:12:15 +0000
+++ ibid/plugins/help.py 2010-01-06 23:10:22 +0000
@@ -1,4 +1,5 @@
1import inspect1import inspect
2import sys
23
3import ibid4import ibid
4from ibid.plugins import Processor, match5from ibid.plugins import Processor, match
@@ -7,7 +8,7 @@
7help = {'help': u'Provides help and usage information about plugins.'}8help = {'help': u'Provides help and usage information about plugins.'}
89
9class Help(Processor):10class Help(Processor):
10 u"""features11 u"""features [for <word>]
11 help [<feature>]12 help [<feature>]
12 usage <feature>"""13 usage <feature>"""
13 feature = 'help'14 feature = 'help'
@@ -64,4 +65,36 @@
64 else:65 else:
65 event.addresponse(u"I don't know how to use %s either", feature)66 event.addresponse(u"I don't know how to use %s either", feature)
6667
68 @match(r'^features\s+(?:for|with)\s+(.*)$')
69 def search (self, event, phrase):
70 features = map(unicode, self._search(phrase))
71 features.sort()
72 if len(features) == 0:
73 event.addresponse(u"I couldn't find that feature.")
74 elif len(features) == 1:
75 event.addresponse(
76 u'The "%s" feature might be what you\'re looking for.',
77 features[0])
78 else:
79 event.addresponse(u"Are you looking for %s?",
80 human_join(features, conjunction='or'))
81
82 def _search (self, phrase):
83 phrase = phrase.lower()
84 matches = set()
85 processor_modules = set()
86 for processor in ibid.processors:
87 if (hasattr(processor, 'feature') and processor.__doc__ and
88 phrase in processor.__doc__.lower()):
89 matches.add(processor.feature)
90 processor_modules.add(sys.modules[processor.__module__])
91
92 for module in processor_modules:
93 if hasattr(module, 'help'):
94 for feature, help in module.help.iteritems():
95 if phrase in feature or phrase in help.lower():
96 matches.add(feature)
97
98 return matches
99
67# vi: set et sta sw=4 ts=4:100# vi: set et sta sw=4 ts=4:

Subscribers

People subscribed via source and target branches