/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: Jelmer Vernooij
  • Date: 2020-04-05 19:11:34 UTC
  • mto: (7490.7.16 work)
  • mto: This revision was merged to the branch mainline in revision 7501.
  • Revision ID: jelmer@jelmer.uk-20200405191134-0aebh8ikiwygxma5
Populate the .gitignore file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2010 Canonical Ltd
 
1
# Copyright (C) 2005-2011 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
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
 
import sys
25
 
import textwrap
26
 
 
27
 
from bzrlib import (
 
26
from . import (
28
27
    commands as _mod_commands,
29
28
    errors,
30
29
    help_topics,
31
30
    osutils,
32
31
    plugin,
 
32
    ui,
 
33
    utextwrap,
33
34
    )
34
35
 
35
36
 
 
37
class NoHelpTopic(errors.BzrError):
 
38
 
 
39
    _fmt = ("No help could be found for '%(topic)s'. "
 
40
            "Please use 'brz help topics' to obtain a list of topics.")
 
41
 
 
42
    def __init__(self, topic):
 
43
        self.topic = topic
 
44
 
 
45
 
36
46
def help(topic=None, outfile=None):
37
47
    """Write the help for the specific topic to outfile"""
38
48
    if outfile is None:
39
 
        outfile = sys.stdout
 
49
        outfile = ui.ui_factory.make_output_stream()
40
50
 
41
51
    indices = HelpIndices()
42
52
 
44
54
    try:
45
55
        topics = indices.search(topic)
46
56
        shadowed_terms = []
47
 
        for index, topic in topics[1:]:
 
57
        for index, topic_obj in topics[1:]:
48
58
            shadowed_terms.append('%s%s' % (index.prefix,
49
 
                topic.get_help_topic()))
 
59
                                            topic_obj.get_help_topic()))
50
60
        source = topics[0][1]
51
61
        outfile.write(source.get_help_text(shadowed_terms))
52
 
    except errors.NoHelpTopic:
 
62
    except NoHelpTopic:
53
63
        if alias is None:
54
64
            raise
55
65
 
56
66
    if alias is not None:
57
 
        outfile.write("'bzr %s' is an alias for 'bzr %s'.\n" % (topic,
58
 
            " ".join(alias)))
 
67
        outfile.write("'brz %s' is an alias for 'brz %s'.\n" % (topic,
 
68
                                                                " ".join(alias)))
59
69
 
60
70
 
61
71
def help_commands(outfile=None):
62
72
    """List all commands"""
63
73
    if outfile is None:
64
 
        outfile = sys.stdout
 
74
        outfile = ui.ui_factory.make_output_stream()
65
75
    outfile.write(_help_commands_to_text('commands'))
66
76
 
67
77
 
96
106
        else:
97
107
            firstline = ''
98
108
        helpstring = '%-*s %s%s' % (max_name, cmd_name, firstline, plugin_name)
99
 
        lines = textwrap.wrap(
 
109
        lines = utextwrap.wrap(
100
110
            helpstring, subsequent_indent=indent,
101
111
            width=width,
102
112
            break_long_words=False)
135
145
            help_topics.HelpTopicIndex(),
136
146
            _mod_commands.HelpCommandIndex(),
137
147
            plugin.PluginsHelpIndex(),
 
148
            help_topics.ConfigOptionHelpIndex(),
138
149
            ]
139
150
 
140
151
    def _check_prefix_uniqueness(self):
141
152
        """Ensure that the index collection is able to differentiate safely."""
142
 
        prefixes = {}
 
153
        prefixes = set()
143
154
        for index in self.search_path:
144
 
            prefixes.setdefault(index.prefix, []).append(index)
145
 
        for prefix, indices in prefixes.items():
146
 
            if len(indices) > 1:
 
155
            prefix = index.prefix
 
156
            if prefix in prefixes:
147
157
                raise errors.DuplicateHelpPrefix(prefix)
 
158
            prefixes.add(prefix)
148
159
 
149
160
    def search(self, topic):
150
161
        """Search for topic across the help search path.
156
167
        self._check_prefix_uniqueness()
157
168
        result = []
158
169
        for index in self.search_path:
159
 
            result.extend([(index, _topic) for _topic in index.get_topics(topic)])
 
170
            result.extend([(index, _topic)
 
171
                           for _topic in index.get_topics(topic)])
160
172
        if not result:
161
 
            raise errors.NoHelpTopic(topic)
 
173
            raise NoHelpTopic(topic)
162
174
        else:
163
175
            return result