]> git.michaelhowe.org Git - packages/b/bup.git/commitdiff
options.py: remove extra newlines in usage string.
authorAvery Pennarun <apenwarr@gmail.com>
Wed, 8 Sep 2010 07:42:39 +0000 (00:42 -0700)
committerAvery Pennarun <apenwarr@gmail.com>
Wed, 8 Sep 2010 07:44:27 +0000 (00:44 -0700)
If the first line after the "--" was a comment (started with whitespace),
then we'd end up printing a double newline instead of a single one after the
synopsis string.

It would also look weird if we had a multi-line comment; the lines would be
separated by blank lines.

'bup damage -?' encountered this problem.

Signed-off-by: Avery Pennarun <apenwarr@gmail.com>
lib/bup/options.py

index 662ade43233fa51579117b1fea3259100ebb6c1f..650e10af38a34f87dabd883f6e354fb7cba50e7a 100644 (file)
@@ -85,10 +85,13 @@ class Options:
             out.append('%s: %s\n' % (first_syn and 'usage' or '   or', l))
             first_syn = False
         out.append('\n')
+        last_was_option = False
         while lines:
             l = lines.pop()
             if l.startswith(' '):
-                out.append('\n%s\n' % l.lstrip())
+                out.append('%s%s\n' % (last_was_option and '\n' or '',
+                                       l.lstrip()))
+                last_was_option = False
             elif l:
                 (flags, extra) = l.split(' ', 1)
                 extra = extra.strip()
@@ -126,8 +129,10 @@ class Options:
                                                 initial_indent=prefix,
                                                 subsequent_indent=' '*28))
                 out.append(argtext + '\n')
+                last_was_option = True
             else:
                 out.append('\n')
+                last_was_option = False
         return ''.join(out).rstrip() + '\n'
 
     def usage(self, msg=""):