~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/help.py

  • Committer: Aaron Bentley
  • Date: 2005-09-19 02:52:24 UTC
  • mto: (1185.1.29)
  • mto: This revision was merged to the branch mainline in revision 1390.
  • Revision ID: aaron.bentley@utoronto.ca-20050919025224-1cc3c70640086e09
TODO re tests

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
24
23
 
25
24
global_help = \
26
25
"""Bazaar-NG -- a free distributed version-control tool
113
112
    outfile.write(doc)
114
113
    if doc[-1] != '\n':
115
114
        outfile.write('\n')
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()
 
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
    
122
122
    if not options:
123
123
        return
 
124
    
124
125
    if outfile == None:
125
126
        outfile = sys.stdout
 
127
 
126
128
    outfile.write('\noptions:\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')
 
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')
140
136
 
141
137
 
142
138
def help_commands(outfile=None):