1 # Copyright (C) 2006-2010 Aaron Bentley <abentley@panoramicfeedback.com>
2 # Gianluca Montecchi <gian@grys.it>
3 # Thomas Gerigk <tgerigk@gmx.de>
4 # W. Trevor King <wking@drexel.edu>
6 # This file is part of Bugs Everywhere.
8 # Bugs Everywhere is free software; you can redistribute it and/or modify it
9 # under the terms of the GNU General Public License as published by the
10 # Free Software Foundation, either version 2 of the License, or (at your
11 # option) any later version.
13 # Bugs Everywhere is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 # General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with Bugs Everywhere. If not, see <http://www.gnu.org/licenses/>.
23 import libbe.command.util
27 class Help (libbe.command.Command):
28 """Print help for given command or topic
31 >>> import libbe.bugdir
32 >>> io = libbe.command.StringInputOutput()
33 >>> io.stdout = sys.stdout
34 >>> ui = libbe.command.UserInterface(io=io)
37 >>> ret = ui.run(cmd, args=['help'])
38 usage: be help [options] [TOPIC]
41 -h, --help Print a help message.
43 --complete Print a list of possible completions.
46 Print help for specified command/topic or list of all commands.
50 def __init__(self, *args, **kwargs):
51 libbe.command.Command.__init__(self, *args, **kwargs)
53 libbe.command.Argument(
54 name='topic', metavar='TOPIC', default=None,
56 completion_callback=self.complete_topic)
59 def _run(self, **params):
60 if params['topic'] == None:
61 if hasattr(self.ui, 'help'):
62 print >> self.stdout, self.ui.help().rstrip('\n')
63 elif params['topic'] in libbe.command.commands():
64 module = libbe.command.get_command(params['topic'])
65 Class = libbe.command.get_command_class(module,params['topic'])
67 self.ui.setup_command(c)
68 print >> self.stdout, c.help().rstrip('\n')
69 elif params['topic'] in TOPICS:
70 print >> self.stdout, TOPICS[params['topic']].rstrip('\n')
72 raise libbe.command.UserError(
73 '"%s" is neither a command nor topic' % params['topic'])
78 Print help for specified command/topic or list of all commands.
81 def complete_topic(self, command, argument, fragment=None):
82 commands = libbe.command.util.complete_command()
83 topics = sorted(TOPICS.keys())
84 return commands + topics