/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: Gustav Hartvigsson
  • Date: 2021-01-09 21:36:27 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20210109213627-h1xwcutzy9m7a99b
Added 'Case Preserving Working Tree Use Cases' from Canonical Wiki

* Addod a page from the Canonical Bazaar wiki
  with information on the scmeatics of case
  perserving filesystems an a case insensitive
  filesystem works.
  
  * Needs re-work, but this will do as it is the
    same inforamoton as what was on the linked
    page in the currint documentation.

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