~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/help.py

  • Committer: Robert Collins
  • Date: 2005-09-06 15:19:44 UTC
  • mto: (1092.3.1)
  • mto: This revision was merged to the branch mainline in revision 1397.
  • Revision ID: robertc@robertcollins.net-20050906151944-04320f095a2abc31
minor refactors to store, create an ImmutableMemoryStore for testing or other such operations

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
25
"""Bazaar-NG -- a free distributed version-control tool
27
 
http://bazaar-vcs.org/
 
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
 
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
 
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
132
 
    options = cmd.options()
 
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
    
133
122
    if not options:
134
123
        return
 
124
    
135
125
    if outfile == None:
136
126
        outfile = sys.stdout
 
127
 
137
128
    outfile.write('\noptions:\n')
138
 
    for option_name, option in sorted(options.items()):
139
 
        l = '    --' + option_name
140
 
        if option.type is not None:
141
 
            l += ' ' + option.argname.upper()
142
 
        short_name = option.short_name()
143
 
        if short_name:
144
 
            assert len(short_name) == 1
145
 
            l += ', -' + short_name
146
 
        l += (30 - len(l)) * ' ' + option.help
147
 
        # TODO: split help over multiple lines with correct indenting and 
148
 
        # wrapping
149
 
        wrapped = textwrap.fill(l, initial_indent='', subsequent_indent=30*' ')
150
 
        outfile.write(wrapped + '\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')
151
136
 
152
137
 
153
138
def help_commands(outfile=None):
170
155
        if cmd_object.hidden:
171
156
            continue
172
157
        print >>outfile, command_usage(cmd_object)
173
 
 
174
 
        plugin_name = cmd_object.plugin_name()
175
 
        print_command_plugin(cmd_object, outfile, '        %s\n')
176
 
 
177
158
        cmd_help = cmd_object.help()
178
159
        if cmd_help:
179
160
            firstline = cmd_help.split('\n', 1)[0]
180
 
            print >>outfile, '        ' + firstline
 
161
            print >>outfile, '    ' + firstline
181
162