Make Gianluca's bug status display optional for `be depend`.
authorW. Trevor King <wking@drexel.edu>
Wed, 14 Jul 2010 23:24:12 +0000 (19:24 -0400)
committerW. Trevor King <wking@drexel.edu>
Wed, 14 Jul 2010 23:24:12 +0000 (19:24 -0400)
You might not want the bug status displayed, e.g. if you were writing
a script that parsed the output of `be depend`.

The new implementation is better anyway since it avoids redundant
display definitions for blocks vs. blocked by.

NEWS
libbe/command/depend.py

diff --git a/NEWS b/NEWS
index 5dff61d5272922488050635d80805b7bc2415088..aff73ac6c70616233d708bc6d4fedb6c65db2959 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,6 @@
+July 14, 2010
+ * Added --show-status to `be depend`.
+
 June 25, 2010
  * Added --tags to `be list`.
 
index d0dd3b335193ae15bbcda2f900ac2f54cd4e1e24..baea5392c1e95e0022dfe2a85b45bbec31ad79e8 100644 (file)
@@ -71,6 +71,11 @@ class Depend (libbe.command.Command):
     abc/b closed
     abc/a blocks:
     abc/b closed
+    >>> ret = ui.run(cmd, {'show-summary':True}, ['/a']) # doctest: +NORMALIZE_WHITESPACE
+    abc/a blocked by:
+    abc/b       Bug B
+    abc/a blocks:
+    abc/b       Bug B
     >>> ret = ui.run(cmd, {'repair':True})
     >>> ret = ui.run(cmd, {'remove':True}, ['/b', '/a'])
     abc/b blocks:
@@ -88,6 +93,8 @@ class Depend (libbe.command.Command):
                     help='Remove dependency (instead of adding it)'),
                 libbe.command.Option(name='show-status', short_name='s',
                     help='Show status of blocking bugs'),
+                libbe.command.Option(name='show-summary', short_name='S',
+                    help='Show summary of blocking bugs'),
                 libbe.command.Option(name='status',
                     help='Only show bugs matching the STATUS specifier',
                     arg=libbe.command.Argument(
@@ -177,27 +184,28 @@ class Depend (libbe.command.Command):
                 add_block(bugA, bugB)
 
         blocked_by = get_blocked_by(bugdir, bugA)
+
         if len(blocked_by) > 0:
             print >> self.stdout, '%s blocked by:' % bugA.id.user()
-            if params['show-status'] == True:
-                print >> self.stdout, \
-                    '\n'.join(['%s\t%s\t%s' % (_bug.id.user(), _bug.status, _bug.summary)
-                               for _bug in blocked_by])
-            else:
-                print >> self.stdout, \
-                    '\n'.join(['%s\t%s'%(_bug.id.user(), _bug.summary) for _bug in blocked_by])
+            print >> self.stdout, \
+                '\n'.join([self.bug_string(_bug, params)
+                           for _bug in blocked_by])
         blocks = get_blocks(bugdir, bugA)
         if len(blocks) > 0:
             print >> self.stdout, '%s blocks:' % bugA.id.user()
-            if params['show-status'] == True:
-                print >> self.stdout, \
-                    '\n'.join(['%s\t%s\t%s' % (_bug.id.user(), _bug.status, _bug.summary)
-                               for _bug in blocks])
-            else:
-                print >> self.stdout, \
-                    '\n'.join(['%s\t%s'%(_bug.id.user(), _bug.summary) for _bug in blocks])
+            print >> self.stdout, \
+                '\n'.join([self.bug_string(_bug, params)
+                           for _bug in blocks])
         return 0
 
+    def bug_string(self, _bug, params):
+        fields = [_bug.id.user()]
+        if params['show-status'] == True:
+            fields.append(_bug.status)
+        if params['show-summary'] == True:
+            fields.append(_bug.summary)
+        return '\t'.join(fields)
+
     def _long_help(self):
         return """
 Set a dependency with the second bug (B) blocking the first bug (A).