1 # Copyright (C) 2006-2010 Aaron Bentley and Panometrics, Inc.
2 # Gianluca Montecchi <gian@grys.it>
3 # Thomas Gerigk <tgerigk@gmx.de>
4 # W. Trevor King <wking@drexel.edu>
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along
17 # with this program; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 import libbe.command.util
26 class Help (libbe.command.Command):
27 """Print help for given command or topic
30 >>> import libbe.bugdir
31 >>> io = libbe.command.StringInputOutput()
32 >>> io.stdout = sys.stdout
33 >>> ui = libbe.command.UserInterface(io=io)
36 >>> ret = ui.run(cmd, args=['help'])
37 usage: be help [options] [TOPIC]
40 -h, --help Print a help message.
42 --complete Print a list of possible completions.
45 Print help for specified command/topic or list of all commands.
49 def __init__(self, *args, **kwargs):
50 libbe.command.Command.__init__(self, *args, **kwargs)
52 libbe.command.Argument(
53 name='topic', metavar='TOPIC', default=None,
55 completion_callback=self.complete_topic)
58 def _run(self, **params):
59 if params['topic'] == None:
60 if hasattr(self.ui, 'help'):
61 print >> self.stdout, self.ui.help().rstrip('\n')
62 elif params['topic'] in libbe.command.commands():
63 module = libbe.command.get_command(params['topic'])
64 Class = libbe.command.get_command_class(module,params['topic'])
66 print >> self.stdout, c.help().rstrip('\n')
67 elif params['topic'] in TOPICS:
68 print >> self.stdout, TOPICS[params['topic']].rstrip('\n')
70 raise libbe.command.UserError(
71 '"%s" is neither a command nor topic' % params['topic'])
76 Print help for specified command/topic or list of all commands.
79 def complete_topic(self, command, argument, fragment=None):
80 commands = libbe.command.util.complete_command()
81 topics = sorted(TOPICS.keys())
82 return commands + topics