~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/help.py

  • Committer: Martin Pool
  • Date: 2006-01-13 08:12:22 UTC
  • mfrom: (1185.63.5 bzr.patches)
  • Revision ID: mbp@sourcefrog.net-20060113081222-6b572004a2ade0cc
[merge] test_hashcache_raise from Denys

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
# executable files with reasonable names.
21
21
 
22
22
# TODO: `help commands --all` should show hidden commands
 
23
import textwrap
23
24
 
24
25
global_help = \
25
26
"""Bazaar-NG -- a free distributed version-control tool
112
113
    outfile.write(doc)
113
114
    if doc[-1] != '\n':
114
115
        outfile.write('\n')
115
 
    
116
 
    help_on_options(cmd_object.takes_options, outfile=None)
117
 
 
118
 
 
119
 
def help_on_options(options, outfile=None):
120
 
    from bzrlib.commands import SHORT_OPTIONS
121
 
    
 
116
    help_on_command_options(cmd_object, outfile)
 
117
 
 
118
 
 
119
def help_on_command_options(cmd, outfile=None):
 
120
    from bzrlib.option import Option
 
121
    options = cmd.options()
122
122
    if not options:
123
123
        return
124
 
    
125
124
    if outfile == None:
126
125
        outfile = sys.stdout
127
 
 
128
126
    outfile.write('\noptions:\n')
129
 
    for on in options:
130
 
        l = '    --' + on
131
 
        for shortname, longname in SHORT_OPTIONS.items():
132
 
            if longname == on:
133
 
                l += ', -' + shortname
134
 
                break
135
 
        outfile.write(l + '\n')
 
127
    for option_name, option in sorted(options.items()):
 
128
        l = '    --' + option_name
 
129
        if option.type is not None:
 
130
            l += ' ' + option.argname.upper()
 
131
        short_name = option.short_name()
 
132
        if short_name:
 
133
            assert len(short_name) == 1
 
134
            l += ', -' + short_name
 
135
        l += (30 - len(l)) * ' ' + option.help
 
136
        # TODO: split help over multiple lines with correct indenting and 
 
137
        # wrapping
 
138
        wrapped = textwrap.fill(l, initial_indent='', subsequent_indent=30*' ')
 
139
        outfile.write(wrapped + '\n')
136
140
 
137
141
 
138
142
def help_commands(outfile=None):