~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/help.py

  • Committer: Martin Pool
  • Date: 2005-05-19 08:31:06 UTC
  • Revision ID: mbp@sourcefrog.net-20050519083106-ebe71562d3bda4a7
- fix typo

Show diffs side-by-side

added added

removed removed

Lines of Context:
56
56
"""
57
57
 
58
58
 
59
 
import sys
60
 
 
61
 
 
62
 
def help(topic=None, outfile = None):
63
 
    if outfile == None:
64
 
        outfile = sys.stdout
 
59
 
 
60
def help(topic=None):
65
61
    if topic == None:
66
 
        outfile.write(global_help)
 
62
        print global_help
67
63
    elif topic == 'commands':
68
 
        help_commands(outfile = outfile)
 
64
        help_commands()
69
65
    else:
70
 
        help_on_command(topic, outfile = outfile)
 
66
        help_on_command(topic)
71
67
 
72
68
 
73
69
def command_usage(cmdname, cmdclass):
92
88
    return s
93
89
 
94
90
 
95
 
def help_on_command(cmdname, outfile = None):
 
91
def help_on_command(cmdname):
96
92
    cmdname = str(cmdname)
97
93
 
98
 
    if outfile == None:
99
 
        outfile = sys.stdout
100
 
 
101
94
    from inspect import getdoc
102
95
    import commands
103
96
    topic, cmdclass = commands.get_cmd_class(cmdname)
106
99
    if doc == None:
107
100
        raise NotImplementedError("sorry, no detailed help yet for %r" % cmdname)
108
101
 
109
 
    outfile.write('usage: ' + command_usage(topic, cmdclass) + '\n')
 
102
    print 'usage:', command_usage(topic, cmdclass)
110
103
 
111
104
    if cmdclass.aliases:
112
 
        outfile.write('aliases: ' + ', '.join(cmdclass.aliases) + '\n')
113
 
    
114
 
    outfile.write(doc)
115
 
    
116
 
    help_on_option(cmdclass.takes_options, outfile = None)
117
 
 
118
 
 
119
 
def help_on_option(options, outfile = None):
 
105
        print 'aliases: ' + ', '.join(cmdclass.aliases)
 
106
    
 
107
    print doc
 
108
    
 
109
    help_on_option(cmdclass.takes_options)
 
110
 
 
111
 
 
112
def help_on_option(options):
120
113
    import commands
121
114
    
122
115
    if not options:
123
116
        return
124
117
    
125
 
    if outfile == None:
126
 
        outfile = sys.stdout
127
 
 
128
 
    outfile.write('\noptions:\n')
 
118
    print
 
119
    print 'options:'
129
120
    for on in options:
130
121
        l = '    --' + on
131
122
        for shortname, longname in commands.SHORT_OPTIONS.items():
132
123
            if longname == on:
133
124
                l += ', -' + shortname
134
125
                break
135
 
        outfile.write(l + '\n')
136
 
 
137
 
 
138
 
def help_commands(outfile = None):
 
126
        print l
 
127
 
 
128
 
 
129
def help_commands():
139
130
    """List all commands"""
140
131
    import inspect
141
132
    import commands
142
 
 
143
 
    if outfile == None:
144
 
        outfile = sys.stdout
145
133
    
146
134
    accu = []
147
135
    for cmdname, cmdclass in commands.get_all_cmds():
150
138
    for cmdname, cmdclass in accu:
151
139
        if cmdclass.hidden:
152
140
            continue
153
 
        outfile.write(command_usage(cmdname, cmdclass) + '\n')
 
141
        print command_usage(cmdname, cmdclass)
154
142
        help = inspect.getdoc(cmdclass)
155
143
        if help:
156
 
            outfile.write("    " + help.split('\n', 1)[0] + '\n')
157
 
 
 
144
            print "    " + help.split('\n', 1)[0]
158
145
            
159
146