~bzr-pqm/bzr/bzr.dev

351 by Martin Pool
- Split out help functions into bzrlib.help
1
# Copyright (C) 2004, 2005 by Canonical Ltd
2
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
17
global_help = \
18
"""Bazaar-NG -- a free distributed version-control tool
19
http://bazaar-ng.org/
20
21
**WARNING: THIS IS AN UNSTABLE DEVELOPMENT VERSION**
22
23
* Metadata format is not stable yet -- you may need to
24
  discard history in the future.
25
26
* Many commands unimplemented or partially implemented.
27
28
* Space-inefficient storage.
29
30
* No merge operators yet.
31
32
Interesting commands:
33
34
  bzr help [COMMAND]
35
      Show help screen
36
  bzr version
37
      Show software version/licence/non-warranty.
38
  bzr init
39
      Start versioning the current directory
40
  bzr add FILE...
41
      Make files versioned.
42
  bzr log
43
      Show revision history.
44
  bzr rename FROM TO
45
      Rename one file.
46
  bzr move FROM... DESTDIR
47
      Move one or more files to a different directory.
48
  bzr diff [FILE...]
49
      Show changes from last revision to working copy.
50
  bzr commit -m 'MESSAGE'
51
      Store current state as new revision.
52
  bzr export [-r REVNO] DESTINATION
53
      Export the branch state at a previous version.
54
  bzr status
55
      Show summary of pending changes.
56
  bzr remove FILE...
57
      Make a file not versioned.
58
  bzr info
59
      Show statistics about this branch.
60
  bzr check
61
      Verify history is stored safely. 
62
  (for more type 'bzr help commands')
63
"""
64
65
66
def help(topic=None):
67
    if topic == None:
68
        print global_help
69
    elif topic == 'commands':
70
        help_commands()
71
    else:
72
        help_on_command(topic)
73
74
75
def help_on_command(cmdname):
76
    cmdname = str(cmdname)
77
78
    from inspect import getdoc
79
    import commands
80
    topic, cmdclass = commands.get_cmd_class(cmdname)
81
82
    doc = getdoc(cmdclass)
83
    if doc == None:
84
        raise NotImplementedError("sorry, no detailed help yet for %r" % cmdname)
85
86
    if '\n' in doc:
87
        short, rest = doc.split('\n', 1)
88
    else:
89
        short = doc
90
        rest = ''
91
92
    print 'usage: bzr ' + topic,
93
    for aname in cmdclass.takes_args:
94
        aname = aname.upper()
95
        if aname[-1] in ['$', '+']:
96
            aname = aname[:-1] + '...'
97
        elif aname[-1] == '?':
98
            aname = '[' + aname[:-1] + ']'
99
        elif aname[-1] == '*':
100
            aname = '[' + aname[:-1] + '...]'
101
        print aname,
102
    print 
103
    print short
352 by Martin Pool
- Show aliases in command help
104
105
    if cmdclass.aliases:
106
        print 'aliases: ' + ', '.join(cmdclass.aliases)
107
    
351 by Martin Pool
- Split out help functions into bzrlib.help
108
    if rest:
109
        print rest
110
111
    help_on_option(cmdclass.takes_options)
112
113
114
def help_on_option(options):
115
    import commands
116
    
117
    if not options:
118
        return
119
    
120
    print
121
    print 'options:'
122
    for on in options:
123
        l = '    --' + on
124
        for shortname, longname in commands.SHORT_OPTIONS.items():
125
            if longname == on:
126
                l += ', -' + shortname
127
                break
128
        print l
129
130
131
def help_commands():
132
    """List all commands"""
133
    import inspect
134
    import commands
135
    
136
    accu = []
137
    for cmdname, cmdclass in commands.get_all_cmds():
138
        accu.append((cmdname, cmdclass))
139
    accu.sort()
140
    for cmdname, cmdclass in accu:
141
        if cmdclass.hidden:
142
            continue
143
        print cmdname
144
        help = inspect.getdoc(cmdclass)
145
        if help:
146
            print "    " + help.split('\n', 1)[0]
147
            
148