~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to __init__.py

  • Committer: Michael Ellerman
  • Date: 2006-06-05 13:46:17 UTC
  • mto: (0.3.1 shelf-dev)
  • mto: This revision was merged to the branch mainline in revision 393.
  • Revision ID: michael@ellerman.id.au-20060605134617-6012ca805dabffbb
Make help for subcommands more readable, print options in help also.

Show diffs side-by-side

added added

removed removed

Lines of Context:
119
119
        raise CommandError("Unknown shelf subcommand '%s'" % cmd_name)
120
120
 
121
121
    def help(self):
122
 
        lines = ["%s\n\nSubcommands:" % self.__doc__]
 
122
        text = ["%s\n\nSubcommands:\n" % self.__doc__]
123
123
 
124
 
        sub_help = []
125
 
        maxlen = 0
126
124
        for cmd_class in self.subcommands:
127
 
            usage = command_usage(cmd_class())
128
 
            usage = usage.replace('bzr shelf-', '')
129
 
            sub_help.append((usage, cmd_class.__doc__))
130
 
            maxlen = max(maxlen, len(usage))
131
 
 
132
 
        for usage, doc in sub_help:
133
 
            lines.append("  %-*s  %s" % (maxlen, usage, doc))
134
 
 
135
 
        return '\n'.join(lines)
 
125
            text.extend(self.sub_help(cmd_class) + ['\n'])
 
126
 
 
127
        return ''.join(text)
 
128
 
 
129
    def sub_help(self, cmd_class):
 
130
        text = []
 
131
        cmd_obj = cmd_class()
 
132
        indent = 2 * ' '
 
133
 
 
134
        usage = command_usage(cmd_obj)
 
135
        usage = usage.replace('bzr shelf-', '')
 
136
        text.append('%s%s\n' % (indent, usage))
 
137
 
 
138
        text.append('%s%s\n' % (2 * indent, cmd_class.__doc__))
 
139
 
 
140
        # Somewhat copied from bzrlib.help.help_on_command_options
 
141
        option_help = []
 
142
        for option_name, option in sorted(cmd_obj.options().items()):
 
143
            if option_name == 'help':
 
144
                continue
 
145
            option_help.append('%s--%s' % (3 * indent, option_name))
 
146
            if option.type is not None:
 
147
                option_help.append(' %s' % option.argname.upper())
 
148
            if option.short_name():
 
149
                option_help.append(', -%s' % option.short_name())
 
150
            option_help.append('%s%s\n' % (2 * indent, option.help))
 
151
 
 
152
        if len(option_help) > 0:
 
153
            text.append('%soptions:\n' % (2 * indent))
 
154
            text.extend(option_help)
 
155
 
 
156
        return text
136
157
 
137
158
 
138
159
class cmd_unshelve(bzrlib.commands.Command):