Rev 2427: ``bzr help`` now provides cross references to other help topics using the in file:///home/robertc/source/baz/see-also/

Robert Collins robertc at robertcollins.net
Thu Apr 19 05:54:29 BST 2007


At file:///home/robertc/source/baz/see-also/

------------------------------------------------------------
revno: 2427
revision-id: robertc at robertcollins.net-20070419045408-uvczw1fcfzprz7ep
parent: robertc at robertcollins.net-20070418083902-4o66h9fk7zeisvwa
committer: Robert Collins <robertc at robertcollins.net>
branch nick: see-also
timestamp: Thu 2007-04-19 14:54:08 +1000
message:
  ``bzr help`` now provides cross references to other help topics using the
  _see_also facility on command classes. (Robert Collins)
added:
  bzrlib/tests/test_help.py      test_help.py-20070419045354-6q6rq15j9e2n5fna-1
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/help.py                 help.py-20050505025907-4dd7a6d63912f894
  bzrlib/tests/__init__.py       selftest.py-20050531073622-8d0e3c8845c97a64
  bzrlib/tests/blackbox/test_help.py test_help.py-20060216004358-4ee8a2a338f75a62
=== added file 'bzrlib/tests/test_help.py'
--- a/bzrlib/tests/test_help.py	1970-01-01 00:00:00 +0000
+++ b/bzrlib/tests/test_help.py	2007-04-19 04:54:08 +0000
@@ -0,0 +1,46 @@
+# Copyright (C) 2007 Canonical Ltd
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+"""Unit tests for the bzrlib.help module."""
+
+from cStringIO import StringIO
+
+from bzrlib import (
+    commands,
+    help,
+    tests,
+    )
+
+
+class TestCommandHelp(tests.TestCase):
+    """Tests for help on commands."""
+
+    def test_command_help_includes_see_also(self):
+        class cmd_WithSeeAlso(commands.Command):
+            """A sample command."""
+            _see_also = ['foo', 'bar']
+        cmd = cmd_WithSeeAlso()
+        helpfile = StringIO()
+        help.help_on_command_object(cmd, 'cmd_sample', helpfile)
+        self.assertEqual('usage: bzr WithSeeAlso\n'
+            '\n'
+            'A sample command.\n'
+            '\n'
+            'Options:\n'
+            '  -h, --help  show help message\n'
+            '\n'
+            'See also: bar, foo\n',
+            helpfile.getvalue())

=== modified file 'NEWS'
--- a/NEWS	2007-04-18 08:39:02 +0000
+++ b/NEWS	2007-04-19 04:54:08 +0000
@@ -8,6 +8,9 @@
     * ``selftest`` has new short options ``-f`` and ``-1``.  (Martin
       Pool)
 
+    * ``bzr help`` now provides cross references to other help topics using
+      the _see_also facility on command classes. (Robert Collins)
+
   INTERNALS:
 
     * bzrlib API compatability with 0.8 has been dropped, cleaning up some

=== modified file 'bzrlib/help.py'
--- a/bzrlib/help.py	2006-12-14 21:45:21 +0000
+++ b/bzrlib/help.py	2007-04-19 04:54:08 +0000
@@ -83,12 +83,21 @@
     from bzrlib.commands import get_cmd_object
 
     cmdname = str(cmdname)
-
-    if outfile is None:
-        outfile = sys.stdout
-
     cmd_object = get_cmd_object(cmdname)
 
+    return help_on_command_object(cmd_object, cmdname, outfile)
+
+
+def help_on_command_object(cmd_object, cmdname, outfile=None):
+    """Generate help on the cmd_object with a supplied name of cmdname.
+
+    :param cmd_object: An instance of a Command.
+    :param cmdname: The user supplied name. This might be an alias for example.
+    :param outfile: A stream to write the help to.
+    """
+    if outfile is None:
+        outfile = sys.stdout
+
     doc = cmd_object.help()
     if doc is None:
         raise NotImplementedError("sorry, no detailed help yet for %r" % cmdname)
@@ -107,6 +116,11 @@
     if doc[-1] != '\n':
         outfile.write('\n')
     help_on_command_options(cmd_object, outfile)
+    see_also = cmd_object.get_see_also()
+    if see_also:
+        outfile.write('\nSee also: ')
+        outfile.write(', '.join(see_also))
+        outfile.write('\n')
 
 
 def help_on_command_options(cmd, outfile=None):

=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py	2007-04-17 07:38:47 +0000
+++ b/bzrlib/tests/__init__.py	2007-04-19 04:54:08 +0000
@@ -2173,6 +2173,7 @@
                    'bzrlib.tests.test_gpg',
                    'bzrlib.tests.test_graph',
                    'bzrlib.tests.test_hashcache',
+                   'bzrlib.tests.test_help',
                    'bzrlib.tests.test_http',
                    'bzrlib.tests.test_http_response',
                    'bzrlib.tests.test_https_ca_bundle',

=== modified file 'bzrlib/tests/blackbox/test_help.py'
--- a/bzrlib/tests/blackbox/test_help.py	2007-02-02 00:16:10 +0000
+++ b/bzrlib/tests/blackbox/test_help.py	2007-04-19 04:54:08 +0000
@@ -91,4 +91,3 @@
         for line in help.split('\n'):
             if '--long' in line:
                 self.assertTrue('show help on all commands' in line)
-



More information about the bazaar-commits mailing list