[SCM] WebKit Debian packaging branch, webkit-1.2, updated. upstream/1.1.90-6072-g9a69373

eric at webkit.org eric at webkit.org
Wed Apr 7 23:51:01 UTC 2010


The following commit has been merged in the webkit-1.2 branch:
commit 6440272e96a55ca4538f9df164145921ca6db962
Author: eric at webkit.org <eric at webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Fri Nov 20 02:18:44 2009 +0000

    2009-11-19  Eric Seidel  <eric at webkit.org>
    
            Reviewed by Adam Barth.
    
            bugzilla-tool needs per-command help
            https://bugs.webkit.org/show_bug.cgi?id=31697
    
            Added support for "bugzilla-tool help command-name"
            and a unit test to make sure it works.
    
            * Scripts/modules/multicommandtool.py:
            * Scripts/modules/multicommandtool_unittest.py:
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@51226 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebKitTools/ChangeLog b/WebKitTools/ChangeLog
index e53e7ac..24e56d6 100644
--- a/WebKitTools/ChangeLog
+++ b/WebKitTools/ChangeLog
@@ -2,6 +2,19 @@
 
         Reviewed by Adam Barth.
 
+        bugzilla-tool needs per-command help
+        https://bugs.webkit.org/show_bug.cgi?id=31697
+
+        Added support for "bugzilla-tool help command-name"
+        and a unit test to make sure it works.
+
+        * Scripts/modules/multicommandtool.py:
+        * Scripts/modules/multicommandtool_unittest.py:
+
+2009-11-19  Eric Seidel  <eric at webkit.org>
+
+        Reviewed by Adam Barth.
+
         Move MultiCommandTool and Command into a separate file and add some basic unit tests
         https://bugs.webkit.org/show_bug.cgi?id=31695
 
diff --git a/WebKitTools/Scripts/modules/multicommandtool.py b/WebKitTools/Scripts/modules/multicommandtool.py
index 6e1d661..4baad51 100644
--- a/WebKitTools/Scripts/modules/multicommandtool.py
+++ b/WebKitTools/Scripts/modules/multicommandtool.py
@@ -35,6 +35,8 @@ import sys
 
 from optparse import OptionParser, IndentedHelpFormatter, SUPPRESS_USAGE, make_option
 
+from modules.logging import log
+
 class Command:
     def __init__(self, help_text, argument_names=None, options=None, requires_local_commits=False):
         self.help_text = help_text
@@ -104,6 +106,10 @@ class MultiCommandTool:
         help_text += command['object'].option_parser.format_option_help(formatter)
         return help_text
 
+    @classmethod
+    def _standalone_help_for_command(cls, command):
+        return cls._help_for_command(command, IndentedHelpFormatter(), len(cls._name_and_arguments(command)))
+
     def _commands_usage(self):
         # Only show commands which are relevant to this checkout.  This might be confusing to some users?
         relevant_commands = filter(self.should_show_command_help, self.commands)
@@ -145,8 +151,9 @@ class MultiCommandTool:
     def should_execute_command(self, command):
         raise NotImplementedError, "subclasses must implement"
 
-    def main(self):
-        (global_args, command_name, args_after_command_name) = self._split_args(sys.argv[1:])
+
+    def main(self, argv=sys.argv):
+        (global_args, command_name, args_after_command_name) = self._split_args(argv[1:])
 
         # Handle --help, etc:
         self.handle_global_args(global_args)
@@ -154,13 +161,22 @@ class MultiCommandTool:
         if not command_name:
             self.global_option_parser.error("No command specified")
 
+        if command_name == "help":
+            if args_after_command_name:
+                command = self.command_by_name(args_after_command_name[0])
+                log(self._standalone_help_for_command(command))
+            else:
+                self.global_option_parser.print_help()
+            return 0
+
         command = self.command_by_name(command_name)
         if not command:
             self.global_option_parser.error(command_name + " is not a recognized command")
 
         (should_execute, failure_reason) = self.should_execute_command(command)
         if not should_execute:
-            error(failure_reason)
+            log(failure_reason)
+            return 0
 
         command_object = command["object"]
         (command_options, command_args) = command_object.parse_args(args_after_command_name)
diff --git a/WebKitTools/Scripts/modules/multicommandtool_unittest.py b/WebKitTools/Scripts/modules/multicommandtool_unittest.py
index 997e11a..49fc71e 100644
--- a/WebKitTools/Scripts/modules/multicommandtool_unittest.py
+++ b/WebKitTools/Scripts/modules/multicommandtool_unittest.py
@@ -26,8 +26,10 @@
 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
+import sys
 import unittest
 from multicommandtool import MultiCommandTool, Command
+from StringIO import StringIO
 
 from optparse import make_option
 
@@ -60,6 +62,17 @@ class TrivialTool(MultiCommandTool):
 
 
 class MultiCommandToolTest(unittest.TestCase):
+
+    def _capture_stderr(self):
+        self.saved_stderr = sys.stderr
+        sys.stderr = StringIO()
+
+    def _release_stderr(self):
+        string = sys.stderr.getvalue()
+        sys.stderr = self.saved_stderr
+        self.saved_stderr = None
+        return string
+
     def _assert_split(self, args, expected_split):
         self.assertEqual(MultiCommandTool._split_args(args), expected_split)
 
@@ -84,6 +97,18 @@ class MultiCommandToolTest(unittest.TestCase):
         self.assertEqual(tool.command_by_name("foo_command"), foo_command)
         self.assertEqual(tool.command_by_name("bar"), None)
 
+    def test_command_help(self):
+        command_with_args = TrivialCommand(options=[make_option("--my_option")])
+        foo_command = { "name" : "foo_command", "object" :  command_with_args }
+        tool = TrivialTool([foo_command])
+
+        self._capture_stderr()
+        exit_code = tool.main(["tool", "help", "foo_command"])
+        help_text = self._release_stderr()
+        expected_subcommand_help = "  foo_command [options]   help text\nOptions:\n  --my_option=MY_OPTION\n\n"
+        self.assertEqual(exit_code, 0)
+        self.assertEqual(help_text, expected_subcommand_help)
+
 
 if __name__ == "__main__":
     unittest.main()

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list