/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
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
104
    if rest:
105
        print rest
106
107
    help_on_option(cmdclass.takes_options)
108
109
110
def help_on_option(options):
111
    import commands
112
    
113
    if not options:
114
        return
115
    
116
    print
117
    print 'options:'
118
    for on in options:
119
        l = '    --' + on
120
        for shortname, longname in commands.SHORT_OPTIONS.items():
121
            if longname == on:
122
                l += ', -' + shortname
123
                break
124
        print l
125
126
127
def help_commands():
128
    """List all commands"""
129
    import inspect
130
    import commands
131
    
132
    accu = []
133
    for cmdname, cmdclass in commands.get_all_cmds():
134
        accu.append((cmdname, cmdclass))
135
    accu.sort()
136
    for cmdname, cmdclass in accu:
137
        if cmdclass.hidden:
138
            continue
139
        print cmdname
140
        help = inspect.getdoc(cmdclass)
141
        if help:
142
            print "    " + help.split('\n', 1)[0]
143
            
144