[PATCH] verbose help (show plugin providing a cmd and hidden cmds)
Robert Widhopf-Fenk
hack at robf.de
Wed Jun 7 23:15:26 BST 2006
Attached is a patch that adds the two new options -v and
--plugin to the "bzr help" command and allows for:
For a list of all commands from all plugins say:
bzr help --plugin "*" commands
For a list of all commands from the plugin "bzrtools" say:
bzr help --plugin bzrtools commands
Use -v to also list hidden commands and by which plugin a command is provided.
The patch also makes "bzr plugins" visible.
Comments welcome,
Robert
-------------- next part --------------
=== modified file 'bzrlib/builtins.py'
--- bzrlib/builtins.py 2006-06-06 18:03:45 +0000
+++ bzrlib/builtins.py 2006-06-07 21:44:33 +0000
@@ -2217,17 +2217,29 @@
class cmd_help(Command):
"""Show help on a command or other topic.
- For a list of all available commands, say 'bzr help commands'."""
- takes_options = [Option('long', 'show help on all commands')]
+ For a list of all available commands, say:
+ bzr help commands
+
+ For a list of all commands from all plugins say:
+ bzr help --plugin "*" commands
+
+ For a list of all commands from the plugin "bzrtools" say:
+ bzr help --plugin bzrtools commands
+
+ Use -v to also list hidden commands and by which plugin a command is provided."""
+ takes_options = [Option('long', 'show help on all commands'),
+ 'verbose',
+ Option('plugin', type=str, argname='pluginname',
+ help='restrict help to the given plugin')]
takes_args = ['topic?']
- aliases = ['?', '--help', '-?', '-h']
+ aliases = ['--help', '-?', '-h']
@display_command
- def run(self, topic=None, long=False):
+ def run(self, topic=None, long=False, verbose=False, plugin=None):
import help
if topic is None and long:
topic = "commands"
- help.help(topic)
+ help.help(topic, verbose = verbose, plugin = plugin)
class cmd_shell_complete(Command):
@@ -2342,7 +2354,6 @@
class cmd_plugins(Command):
"""List plugins"""
- hidden = True
@display_command
def run(self):
import bzrlib.plugin
=== modified file 'bzrlib/help.py'
--- bzrlib/help.py 2006-05-10 17:48:25 +0000
+++ bzrlib/help.py 2006-06-07 22:04:46 +0000
@@ -52,15 +52,15 @@
import sys
-def help(topic=None, outfile = None):
+def help(topic=None, outfile = None, verbose = False, plugin = None):
if outfile == None:
outfile = sys.stdout
if topic == None:
outfile.write(global_help)
elif topic == 'commands':
- help_commands(outfile = outfile)
+ help_commands(outfile = outfile, verbose = verbose, plugin = plugin)
else:
- help_on_command(topic, outfile = outfile)
+ help_on_command(topic, outfile = outfile, verbose = verbose)
def command_usage(cmd_object):
@@ -85,7 +85,7 @@
return s
-def help_on_command(cmdname, outfile=None):
+def help_on_command(cmdname, outfile=None, verbose=False):
from bzrlib.commands import get_cmd_object
cmdname = str(cmdname)
@@ -95,6 +95,11 @@
cmd_object = get_cmd_object(cmdname)
+ if verbose:
+ if cmd_object.__module__.split(".")[1] == "plugins":
+ cmd_plugin = cmd_object.__module__.split(".")[2]
+ print >>outfile, '(from plugin "' + cmd_plugin + '")\n'
+
doc = cmd_object.help()
if doc == None:
raise NotImplementedError("sorry, no detailed help yet for %r" % cmdname)
@@ -136,7 +141,7 @@
outfile.write(wrapped + '\n')
-def help_commands(outfile=None):
+def help_commands(outfile=None, verbose=False, plugin=None):
"""List all commands"""
from bzrlib.commands import (builtin_command_names,
plugin_command_names,
@@ -153,9 +158,24 @@
for cmd_name in names:
cmd_object = get_cmd_object(cmd_name)
- if cmd_object.hidden:
- continue
+ if cmd_object.hidden and not verbose:
+ continue
+ is_plugin = cmd_object.__module__.split(".")[1] == "plugins"
+ if is_plugin:
+ plugin_name = cmd_object.__module__.split(".")[2]
+ if plugin and (not is_plugin or
+ (plugin != '*' and plugin != plugin_name)):
+ continue
+
print >>outfile, command_usage(cmd_object)
+ if verbose and (cmd_object.hidden or is_plugin):
+ hints = []
+ if cmd_object.hidden:
+ hints.append('hidden')
+ if is_plugin:
+ hints.append("plugin '" + plugin_name + "'")
+ print >>outfile, ' (' + ', '.join(hints) + ')'
+
cmd_help = cmd_object.help()
if cmd_help:
firstline = cmd_help.split('\n', 1)[0]
More information about the bazaar
mailing list