~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/help.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2006-08-18 18:17:19 UTC
  • mfrom: (1711.2.133 jam-integration)
  • Revision ID: pqm@pqm.ubuntu.com-20060818181719-90004a4648d8537a
(cfbolz,hpk,robertc,jam) Add SFTP benchmark tests, and tests across a delayed socket

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2004, 2005 by Canonical Ltd
2
 
 
 
1
# Copyright (C) 2004, 2005, 2006 by Canonical Ltd
 
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
5
5
# the Free Software Foundation; either version 2 of the License, or
6
6
# (at your option) any later version.
7
 
 
 
7
#
8
8
# This program is distributed in the hope that it will be useful,
9
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
11
# GNU General Public License for more details.
12
 
 
 
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20
20
# executable files with reasonable names.
21
21
 
22
22
# TODO: `help commands --all` should show hidden commands
 
23
import textwrap
23
24
 
24
25
global_help = \
25
 
"""Bazaar-NG -- a free distributed version-control tool
26
 
http://bazaar-ng.org/
27
 
 
28
 
WARNING: This is an unstable development version.
29
 
         Please keep backups.
 
26
"""Bazaar -- a free distributed version-control tool
 
27
http://bazaar-vcs.org/
30
28
 
31
29
Basic commands:
32
30
 
87
85
    return s
88
86
 
89
87
 
 
88
def print_command_plugin(cmd_object, outfile, format):
 
89
    """Print the plugin that provides a command object, if any.
 
90
 
 
91
    If the cmd_object is provided by a plugin, prints the plugin name to
 
92
    outfile using the provided format string.
 
93
    """
 
94
    plugin_name = cmd_object.plugin_name()
 
95
    if plugin_name is not None:
 
96
        out_str = '(From plugin "%s")' % plugin_name
 
97
        outfile.write(format % out_str)
 
98
 
 
99
 
90
100
def help_on_command(cmdname, outfile=None):
91
101
    from bzrlib.commands import get_cmd_object
92
102
 
109
119
 
110
120
    print >>outfile
111
121
 
 
122
    print_command_plugin(cmd_object, outfile, '%s\n\n')
 
123
 
112
124
    outfile.write(doc)
113
125
    if doc[-1] != '\n':
114
126
        outfile.write('\n')
115
 
    
116
 
    help_on_options(cmd_object.takes_options, outfile=None)
117
 
 
118
 
 
119
 
def help_on_options(options, outfile=None):
120
 
    from bzrlib.commands import SHORT_OPTIONS
121
 
    
122
 
    if not options:
123
 
        return
124
 
    
125
 
    if outfile == None:
 
127
    help_on_command_options(cmd_object, outfile)
 
128
 
 
129
 
 
130
def help_on_command_options(cmd, outfile=None):
 
131
    from bzrlib.option import Option, get_optparser
 
132
    if outfile is None:
126
133
        outfile = sys.stdout
127
 
 
128
 
    outfile.write('\noptions:\n')
129
 
    for on in options:
130
 
        l = '    --' + on
131
 
        for shortname, longname in SHORT_OPTIONS.items():
132
 
            if longname == on:
133
 
                l += ', -' + shortname
134
 
                break
135
 
        outfile.write(l + '\n')
 
134
    options = cmd.options()
 
135
    outfile.write('\n')
 
136
    outfile.write(get_optparser(options).format_option_help())
136
137
 
137
138
 
138
139
def help_commands(outfile=None):
155
156
        if cmd_object.hidden:
156
157
            continue
157
158
        print >>outfile, command_usage(cmd_object)
 
159
 
 
160
        plugin_name = cmd_object.plugin_name()
 
161
        print_command_plugin(cmd_object, outfile, '        %s\n')
 
162
 
158
163
        cmd_help = cmd_object.help()
159
164
        if cmd_help:
160
165
            firstline = cmd_help.split('\n', 1)[0]
161
 
            print >>outfile, '    ' + firstline
 
166
            print >>outfile, '        ' + firstline
162
167