~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/help.py

  • Committer: Martin Pool
  • Date: 2005-06-06 13:24:18 UTC
  • Revision ID: mbp@sourcefrog.net-20050606132418-1082c87e2473e266
- manpage generator by Hans Ulrich Niedermann

Show diffs side-by-side

added added

removed removed

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