/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 bzrlib/help.py

  • Committer: Andrew Bennetts
  • Date: 2011-06-09 07:38:32 UTC
  • mto: This revision was merged to the branch mainline in revision 5964.
  • Revision ID: andrew.bennetts@canonical.com-20110609073832-dt6oww033iexli4l
Fix thinko in wording regarding stacking invariants and revisions with multiple parents.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2011 Canonical Ltd
 
1
# Copyright (C) 2005-2010 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
21
21
 
22
22
# TODO: `help commands --all` should show hidden commands
23
23
 
24
 
from . import (
 
24
import sys
 
25
import textwrap
 
26
 
 
27
from bzrlib import (
25
28
    commands as _mod_commands,
26
29
    errors,
27
30
    help_topics,
28
31
    osutils,
29
32
    plugin,
30
 
    ui,
31
 
    utextwrap,
32
33
    )
33
34
 
34
35
 
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
36
def help(topic=None, outfile=None):
45
37
    """Write the help for the specific topic to outfile"""
46
38
    if outfile is None:
47
 
        outfile = ui.ui_factory.make_output_stream()
 
39
        outfile = sys.stdout
48
40
 
49
41
    indices = HelpIndices()
50
42
 
54
46
        shadowed_terms = []
55
47
        for index, topic_obj in topics[1:]:
56
48
            shadowed_terms.append('%s%s' % (index.prefix,
57
 
                                            topic_obj.get_help_topic()))
 
49
                topic_obj.get_help_topic()))
58
50
        source = topics[0][1]
59
51
        outfile.write(source.get_help_text(shadowed_terms))
60
 
    except NoHelpTopic:
 
52
    except errors.NoHelpTopic:
61
53
        if alias is None:
62
54
            raise
63
55
 
64
56
    if alias is not None:
65
 
        outfile.write("'brz %s' is an alias for 'brz %s'.\n" % (topic,
66
 
                                                                " ".join(alias)))
 
57
        outfile.write("'bzr %s' is an alias for 'bzr %s'.\n" % (topic,
 
58
            " ".join(alias)))
67
59
 
68
60
 
69
61
def help_commands(outfile=None):
70
62
    """List all commands"""
71
63
    if outfile is None:
72
 
        outfile = ui.ui_factory.make_output_stream()
 
64
        outfile = sys.stdout
73
65
    outfile.write(_help_commands_to_text('commands'))
74
66
 
75
67
 
104
96
        else:
105
97
            firstline = ''
106
98
        helpstring = '%-*s %s%s' % (max_name, cmd_name, firstline, plugin_name)
107
 
        lines = utextwrap.wrap(
 
99
        lines = textwrap.wrap(
108
100
            helpstring, subsequent_indent=indent,
109
101
            width=width,
110
102
            break_long_words=False)
143
135
            help_topics.HelpTopicIndex(),
144
136
            _mod_commands.HelpCommandIndex(),
145
137
            plugin.PluginsHelpIndex(),
146
 
            help_topics.ConfigOptionHelpIndex(),
147
138
            ]
148
139
 
149
140
    def _check_prefix_uniqueness(self):
150
141
        """Ensure that the index collection is able to differentiate safely."""
151
 
        prefixes = set()
 
142
        prefixes = {}
152
143
        for index in self.search_path:
153
 
            prefix = index.prefix
154
 
            if prefix in prefixes:
 
144
            prefixes.setdefault(index.prefix, []).append(index)
 
145
        for prefix, indices in prefixes.items():
 
146
            if len(indices) > 1:
155
147
                raise errors.DuplicateHelpPrefix(prefix)
156
 
            prefixes.add(prefix)
157
148
 
158
149
    def search(self, topic):
159
150
        """Search for topic across the help search path.
165
156
        self._check_prefix_uniqueness()
166
157
        result = []
167
158
        for index in self.search_path:
168
 
            result.extend([(index, _topic)
169
 
                           for _topic in index.get_topics(topic)])
 
159
            result.extend([(index, _topic) for _topic in index.get_topics(topic)])
170
160
        if not result:
171
 
            raise NoHelpTopic(topic)
 
161
            raise errors.NoHelpTopic(topic)
172
162
        else:
173
163
            return result