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

  • Committer: Breezy landing bot
  • Author(s): Colin Watson
  • Date: 2020-11-16 21:47:08 UTC
  • mfrom: (7521.1.1 remove-lp-workaround)
  • Revision ID: breezy.the.bot@gmail.com-20201116214708-jos209mgxi41oy15
Remove breezy.git workaround for bazaar.launchpad.net.

Merged from https://code.launchpad.net/~cjwatson/brz/remove-lp-workaround/+merge/393710

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