/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to brzlib/help.py

  • Committer: Jelmer Vernooij
  • Date: 2017-05-21 12:41:27 UTC
  • mto: This revision was merged to the branch mainline in revision 6623.
  • Revision ID: jelmer@jelmer.uk-20170521124127-iv8etg0vwymyai6y
s/bzr/brz/ in apport config.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
 
17
from __future__ import absolute_import
 
18
 
17
19
# TODO: Some way to get a list of external commands (defined by shell
18
20
# scripts) so that they can be included in the help listing as well.
19
21
# It should be enough to just list the plugin directory and look for
21
23
 
22
24
# TODO: `help commands --all` should show hidden commands
23
25
 
24
 
from . import (
 
26
import sys
 
27
 
 
28
from brzlib import (
25
29
    commands as _mod_commands,
26
30
    errors,
27
31
    help_topics,
32
36
    )
33
37
 
34
38
 
35
 
class NoHelpTopic(errors.BzrError):
36
 
 
37
 
    _fmt = ("No help could be found for '%(topic)s'. "
38
 
            "Please use 'brz help topics' to obtain a list of topics.")
39
 
 
40
 
    def __init__(self, topic):
41
 
        self.topic = topic
42
 
 
43
 
 
44
39
def help(topic=None, outfile=None):
45
40
    """Write the help for the specific topic to outfile"""
46
41
    if outfile is None:
54
49
        shadowed_terms = []
55
50
        for index, topic_obj in topics[1:]:
56
51
            shadowed_terms.append('%s%s' % (index.prefix,
57
 
                                            topic_obj.get_help_topic()))
 
52
                topic_obj.get_help_topic()))
58
53
        source = topics[0][1]
59
54
        outfile.write(source.get_help_text(shadowed_terms))
60
 
    except NoHelpTopic:
 
55
    except errors.NoHelpTopic:
61
56
        if alias is None:
62
57
            raise
63
58
 
64
59
    if alias is not None:
65
 
        outfile.write("'brz %s' is an alias for 'brz %s'.\n" % (topic,
66
 
                                                                " ".join(alias)))
 
60
        outfile.write("'bzr %s' is an alias for 'bzr %s'.\n" % (topic,
 
61
            " ".join(alias)))
67
62
 
68
63
 
69
64
def help_commands(outfile=None):
148
143
 
149
144
    def _check_prefix_uniqueness(self):
150
145
        """Ensure that the index collection is able to differentiate safely."""
151
 
        prefixes = set()
 
146
        prefixes = {}
152
147
        for index in self.search_path:
153
 
            prefix = index.prefix
154
 
            if prefix in prefixes:
 
148
            prefixes.setdefault(index.prefix, []).append(index)
 
149
        for prefix, indices in prefixes.items():
 
150
            if len(indices) > 1:
155
151
                raise errors.DuplicateHelpPrefix(prefix)
156
 
            prefixes.add(prefix)
157
152
 
158
153
    def search(self, topic):
159
154
        """Search for topic across the help search path.
165
160
        self._check_prefix_uniqueness()
166
161
        result = []
167
162
        for index in self.search_path:
168
 
            result.extend([(index, _topic)
169
 
                           for _topic in index.get_topics(topic)])
 
163
            result.extend([(index, _topic) for _topic in index.get_topics(topic)])
170
164
        if not result:
171
 
            raise NoHelpTopic(topic)
 
165
            raise errors.NoHelpTopic(topic)
172
166
        else:
173
167
            return result