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

  • Committer: John Arbash Meinel
  • Date: 2005-09-15 21:35:53 UTC
  • mfrom: (907.1.57)
  • mto: (1393.2.1)
  • mto: This revision was merged to the branch mainline in revision 1396.
  • Revision ID: john@arbash-meinel.com-20050915213552-a6c83a5ef1e20897
(broken) Transport work is merged in. Tests do not pass yet.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2004, 2005, 2006 by Canonical Ltd
2
 
#
 
1
# Copyright (C) 2004, 2005 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
24
23
 
25
24
global_help = \
26
 
"""Bazaar -- a free distributed version-control tool
27
 
http://bazaar-vcs.org/
 
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.
28
30
 
29
31
Basic commands:
30
32
 
31
 
  bzr init           makes this directory a versioned branch
32
 
  bzr branch         make a copy of another branch
33
 
 
34
 
  bzr add            make files or directories versioned
35
 
  bzr ignore         ignore a file or pattern
36
 
  bzr mv             move or rename a versioned file
37
 
 
38
 
  bzr status         summarize changes in working copy
39
 
  bzr diff           show detailed diffs
40
 
 
41
 
  bzr merge          pull in changes from another branch
42
 
  bzr commit         save some or all changes
43
 
 
44
 
  bzr log            show history of changes
45
 
  bzr check          validate storage
46
 
 
47
 
  bzr help init      more help on e.g. init command
48
 
  bzr help commands  list all commands
 
33
  bzr init      makes this branch versioned
 
34
  bzr branch    make a copy of another branch
 
35
 
 
36
  bzr add       make files or directories versioned
 
37
  bzr ignore    ignore a file or pattern
 
38
  bzr mv        move or rename a versioned file
 
39
 
 
40
  bzr status    summarize changes in working copy
 
41
  bzr diff      show detailed diffs
 
42
 
 
43
  bzr merge     pull in changes from another branch
 
44
  bzr commit    save some or all changes
 
45
 
 
46
  bzr log       show history of changes
 
47
  bzr check     validate storage
 
48
 
 
49
Use e.g. 'bzr help init' for more details, or
 
50
'bzr help commands' for all commands.
49
51
"""
50
52
 
51
53
 
53
55
 
54
56
 
55
57
def help(topic=None, outfile = None):
56
 
    if outfile is None:
 
58
    if outfile == None:
57
59
        outfile = sys.stdout
58
 
    if topic is None:
 
60
    if topic == None:
59
61
        outfile.write(global_help)
60
62
    elif topic == 'commands':
61
63
        help_commands(outfile = outfile)
85
87
    return s
86
88
 
87
89
 
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
 
 
100
90
def help_on_command(cmdname, outfile=None):
101
91
    from bzrlib.commands import get_cmd_object
102
92
 
103
93
    cmdname = str(cmdname)
104
94
 
105
 
    if outfile is None:
 
95
    if outfile == None:
106
96
        outfile = sys.stdout
107
97
 
108
98
    cmd_object = get_cmd_object(cmdname)
109
99
 
110
100
    doc = cmd_object.help()
111
 
    if doc is None:
 
101
    if doc == None:
112
102
        raise NotImplementedError("sorry, no detailed help yet for %r" % cmdname)
113
103
 
114
104
    print >>outfile, 'usage:', command_usage(cmd_object) 
119
109
 
120
110
    print >>outfile
121
111
 
122
 
    print_command_plugin(cmd_object, outfile, '%s\n\n')
123
 
 
124
112
    outfile.write(doc)
125
113
    if doc[-1] != '\n':
126
114
        outfile.write('\n')
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:
 
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:
133
126
        outfile = sys.stdout
134
 
    options = cmd.options()
135
 
    outfile.write('\n')
136
 
    outfile.write(get_optparser(options).format_option_help())
 
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')
137
136
 
138
137
 
139
138
def help_commands(outfile=None):
142
141
                                 plugin_command_names,
143
142
                                 get_cmd_object)
144
143
 
145
 
    if outfile is None:
 
144
    if outfile == None:
146
145
        outfile = sys.stdout
147
146
 
148
147
    names = set()                       # to eliminate duplicates
156
155
        if cmd_object.hidden:
157
156
            continue
158
157
        print >>outfile, command_usage(cmd_object)
159
 
 
160
 
        plugin_name = cmd_object.plugin_name()
161
 
        print_command_plugin(cmd_object, outfile, '        %s\n')
162
 
 
163
158
        cmd_help = cmd_object.help()
164
159
        if cmd_help:
165
160
            firstline = cmd_help.split('\n', 1)[0]
166
 
            print >>outfile, '        ' + firstline
 
161
            print >>outfile, '    ' + firstline
167
162