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

Proposed by Max Rabkin on 2010-01-06
Status: Merged
Approved by: Jonathan Hitchcock on 2010-01-07
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 on 2010-01-07
Michael Gorven Approve on 2010-01-07
Stefano Rivera 2010-01-06 Approve on 2010-01-07
Review via email: mp+16934@code.launchpad.net
To post a comment you must log in.
Max Rabkin (max-rabkin) wrote :

Suggestions for alternative syntaxes if you have them, please.

Stefano Rivera (stefanor) wrote :

Can't complain

review: Approve
Michael Gorven (mgorven) wrote :

Nice
 review approve

review: Approve
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
1=== modified file 'ibid/plugins/help.py'
2--- ibid/plugins/help.py 2009-12-30 15:12:15 +0000
3+++ ibid/plugins/help.py 2010-01-06 23:10:22 +0000
4@@ -1,4 +1,5 @@
5 import inspect
6+import sys
7
8 import ibid
9 from ibid.plugins import Processor, match
10@@ -7,7 +8,7 @@
11 help = {'help': u'Provides help and usage information about plugins.'}
12
13 class Help(Processor):
14- u"""features
15+ u"""features [for <word>]
16 help [<feature>]
17 usage <feature>"""
18 feature = 'help'
19@@ -64,4 +65,36 @@
20 else:
21 event.addresponse(u"I don't know how to use %s either", feature)
22
23+ @match(r'^features\s+(?:for|with)\s+(.*)$')
24+ def search (self, event, phrase):
25+ features = map(unicode, self._search(phrase))
26+ features.sort()
27+ if len(features) == 0:
28+ event.addresponse(u"I couldn't find that feature.")
29+ elif len(features) == 1:
30+ event.addresponse(
31+ u'The "%s" feature might be what you\'re looking for.',
32+ features[0])
33+ else:
34+ event.addresponse(u"Are you looking for %s?",
35+ human_join(features, conjunction='or'))
36+
37+ def _search (self, phrase):
38+ phrase = phrase.lower()
39+ matches = set()
40+ processor_modules = set()
41+ for processor in ibid.processors:
42+ if (hasattr(processor, 'feature') and processor.__doc__ and
43+ phrase in processor.__doc__.lower()):
44+ matches.add(processor.feature)
45+ processor_modules.add(sys.modules[processor.__module__])
46+
47+ for module in processor_modules:
48+ if hasattr(module, 'help'):
49+ for feature, help in module.help.iteritems():
50+ if phrase in feature or phrase in help.lower():
51+ matches.add(feature)
52+
53+ return matches
54+
55 # vi: set et sta sw=4 ts=4:

Subscribers

People subscribed via source and target branches