~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/help.py

  • Committer: Robert Collins
  • Date: 2007-04-20 00:06:46 UTC
  • mto: This revision was merged to the branch mainline in revision 2441.
  • Revision ID: robertc@robertcollins.net-20070420000646-nwrkgumqaykrg1lz
Create a HelpContexts object to do help lookups.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
import textwrap
26
26
 
27
27
from bzrlib import (
 
28
    commands as _mod_commands,
28
29
    help_topics,
29
30
    osutils,
30
31
    )
80
81
 
81
82
 
82
83
def help_on_command(cmdname, outfile=None):
83
 
    from bzrlib.commands import get_cmd_object
84
 
 
85
84
    cmdname = str(cmdname)
86
 
    cmd_object = get_cmd_object(cmdname)
 
85
    cmd_object = _mod_commands.get_cmd_object(cmdname)
87
86
 
88
87
    return help_on_command_object(cmd_object, cmdname, outfile)
89
88
 
141
140
 
142
141
def _help_commands_to_text(topic):
143
142
    """Generate the help text for the list of commands"""
144
 
    from bzrlib.commands import (builtin_command_names,
145
 
                                 plugin_command_names,
146
 
                                 get_cmd_object)
147
143
    out = []
148
144
    if topic == 'hidden-commands':
149
145
        hidden = True
150
146
    else:
151
147
        hidden = False
152
 
    names = set(builtin_command_names()) # to eliminate duplicates
153
 
    names.update(plugin_command_names())
154
 
    commands = ((n, get_cmd_object(n)) for n in names)
 
148
    names = set(_mod_commands.builtin_command_names()) # to eliminate duplicates
 
149
    names.update(_mod_commands.plugin_command_names())
 
150
    commands = ((n, _mod_commands.get_cmd_object(n)) for n in names)
155
151
    shown_commands = [(n, o) for n, o in commands if o.hidden == hidden]
156
152
    max_name = max(len(n) for n, o in shown_commands)
157
153
    indent = ' ' * (max_name + 1)
183
179
help_topics.topic_registry.register("hidden-commands",
184
180
                                    _help_commands_to_text,
185
181
                                    "All hidden commands")
 
182
 
 
183
 
 
184
class HelpContexts(object):
 
185
    """An object to manage help in multiple contexts."""
 
186
 
 
187
    def __init__(self):
 
188
        self.search_path = [
 
189
            help_topics.HelpTopicContext(),
 
190
            _mod_commands.HelpCommandContext(),
 
191
            ]