~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/help.py

  • Committer: Martin Pool
  • Date: 2005-05-30 01:34:23 UTC
  • Revision ID: mbp@sourcefrog.net-20050530013423-a761697104207995
todo

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
 
    if doc[-1] != '\n':
116
 
        outfile.write('\n')
117
 
    
118
 
    help_on_option(cmdclass.takes_options, outfile = None)
119
 
 
120
 
 
121
 
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):
122
113
    import commands
123
114
    
124
115
    if not options:
125
116
        return
126
117
    
127
 
    if outfile == None:
128
 
        outfile = sys.stdout
129
 
 
130
 
    outfile.write('\noptions:\n')
 
118
    print
 
119
    print 'options:'
131
120
    for on in options:
132
121
        l = '    --' + on
133
122
        for shortname, longname in commands.SHORT_OPTIONS.items():
134
123
            if longname == on:
135
124
                l += ', -' + shortname
136
125
                break
137
 
        outfile.write(l + '\n')
138
 
 
139
 
 
140
 
def help_commands(outfile = None):
 
126
        print l
 
127
 
 
128
 
 
129
def help_commands():
141
130
    """List all commands"""
142
131
    import inspect
143
132
    import commands
144
 
 
145
 
    if outfile == None:
146
 
        outfile = sys.stdout
147
133
    
148
134
    accu = []
149
135
    for cmdname, cmdclass in commands.get_all_cmds():
152
138
    for cmdname, cmdclass in accu:
153
139
        if cmdclass.hidden:
154
140
            continue
155
 
        outfile.write(command_usage(cmdname, cmdclass) + '\n')
 
141
        print command_usage(cmdname, cmdclass)
156
142
        help = inspect.getdoc(cmdclass)
157
143
        if help:
158
 
            outfile.write("    " + help.split('\n', 1)[0] + '\n')
159
 
 
 
144
            print "    " + help.split('\n', 1)[0]
160
145
            
161
146