/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/commands.py

  • Committer: John Arbash Meinel
  • Date: 2009-02-13 21:21:25 UTC
  • mfrom: (3995.3.8 1.12)
  • mto: This revision was merged to the branch mainline in revision 4007.
  • Revision ID: john@arbash-meinel.com-20090213212125-aiqf2d1as2pd2xy2
Merge bzr 1.12 final

Show diffs side-by-side

added added

removed removed

Lines of Context:
346
346
            raise NotImplementedError("sorry, no detailed help yet for %r" % self.name())
347
347
 
348
348
        # Extract the summary (purpose) and sections out from the text
349
 
        purpose,sections = self._get_help_parts(doc)
 
349
        purpose,sections,order = self._get_help_parts(doc)
350
350
 
351
351
        # If a custom usage section was provided, use it
352
352
        if sections.has_key('Usage'):
384
384
        # Add the custom sections (e.g. Examples). Note that there's no need
385
385
        # to indent these as they must be indented already in the source.
386
386
        if sections:
387
 
            labels = sorted(sections.keys())
388
 
            for label in labels:
389
 
                result += ':%s:\n%s\n\n' % (label,sections[label])
 
387
            for label in order:
 
388
                if sections.has_key(label):
 
389
                    result += ':%s:\n%s\n\n' % (label,sections[label])
390
390
 
391
391
        # Add the aliases, source (plug-in) and see also links, if any
392
392
        if self.aliases:
421
421
    def _get_help_parts(text):
422
422
        """Split help text into a summary and named sections.
423
423
 
424
 
        :return: (summary,sections) where summary is the top line and
 
424
        :return: (summary,sections,order) where summary is the top line and
425
425
            sections is a dictionary of the rest indexed by section name.
 
426
            order is the order the section appear in the text.
426
427
            A section starts with a heading line of the form ":xxx:".
427
428
            Indented text on following lines is the section value.
428
429
            All text found outside a named section is assigned to the
429
430
            default section which is given the key of None.
430
431
        """
431
 
        def save_section(sections, label, section):
 
432
        def save_section(sections, order, label, section):
432
433
            if len(section) > 0:
433
434
                if sections.has_key(label):
434
435
                    sections[label] += '\n' + section
435
436
                else:
 
437
                    order.append(label)
436
438
                    sections[label] = section
437
439
 
438
440
        lines = text.rstrip().splitlines()
439
441
        summary = lines.pop(0)
440
442
        sections = {}
 
443
        order = []
441
444
        label,section = None,''
442
445
        for line in lines:
443
446
            if line.startswith(':') and line.endswith(':') and len(line) > 2:
444
 
                save_section(sections, label, section)
 
447
                save_section(sections, order, label, section)
445
448
                label,section = line[1:-1],''
446
449
            elif (label is not None) and len(line) > 1 and not line[0].isspace():
447
 
                save_section(sections, label, section)
 
450
                save_section(sections, order, label, section)
448
451
                label,section = None,line
449
452
            else:
450
453
                if len(section) > 0:
451
454
                    section += '\n' + line
452
455
                else:
453
456
                    section = line
454
 
        save_section(sections, label, section)
455
 
        return summary, sections
 
457
        save_section(sections, order, label, section)
 
458
        return summary, sections, order
456
459
 
457
460
    def get_help_topic(self):
458
461
        """Return the commands help topic - its name."""