diff options
author | W. Trevor King <wking@drexel.edu> | 2009-12-14 20:33:35 -0500 |
---|---|---|
committer | W. Trevor King <wking@drexel.edu> | 2009-12-14 20:33:35 -0500 |
commit | f9ee7a537561be80b9c232dd4fc848ddb564f6b0 (patch) | |
tree | 7534b7415aa5de13a6b2bbdba817561cb8a72592 /libbe/command/help.py | |
parent | 0f87a22c20a019f49455005542d4c60216ce39d2 (diff) | |
download | bugseverywhere-f9ee7a537561be80b9c232dd4fc848ddb564f6b0.tar.gz |
Transitioned help to Command-format
Diffstat (limited to 'libbe/command/help.py')
-rw-r--r-- | libbe/command/help.py | 93 |
1 files changed, 52 insertions, 41 deletions
diff --git a/libbe/command/help.py b/libbe/command/help.py index 9e6d1aa..c8d700d 100644 --- a/libbe/command/help.py +++ b/libbe/command/help.py @@ -16,55 +16,66 @@ # 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., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -"""Print help for given subcommand""" -from libbe import cmdutil, utility -__desc__ = __doc__ -def execute(args, manipulate_encodings=True, restrict_file_access=False, - dir="."): - """ - Print help of specified command (the manipulate_encodings argument - is ignored). +import libbe +import libbe.command +import libbe.command.util + +TOPICS = {} + +class Help (libbe.command.Command): + """Print help for given command or topic + + >>> import sys + >>> import libbe.bugdir + >>> cmd = Help() + >>> cmd._setup_io = lambda i_enc,o_enc : None + >>> cmd.stdout = sys.stdout - >>> execute(["help"]) - Usage: be help [COMMAND] + >>> ret = cmd.run(args=['help']) + usage: be help [options] [TOPIC] <BLANKLINE> Options: - -h, --help Print a help message - --complete Print a list of available completions + -h, --help Print a help message. <BLANKLINE> - Print help for specified command or list of all commands. + --complete Print a list of possible completions. <BLANKLINE> + <BLANKLINE> + Print help for specified command/topic or list of all commands. """ - parser = get_parser() - options, args = parser.parse_args(args) - complete(options, args, parser) - if len(args) > 1: - raise cmdutil.UsageError("Too many arguments.") - if len(args) == 0: - print cmdutil.help() - else: - try: - print cmdutil.help(args[0]) - except AttributeError: - print "No help available" + name = 'help' -def get_parser(): - parser = cmdutil.CmdOptionParser("be help [COMMAND]") - return parser + def __init__(self, *args, **kwargs): + libbe.command.Command.__init__(self, *args, **kwargs) + self.args.extend([ + libbe.command.Argument( + name='topic', metavar='TOPIC', default=None, + optional=True, + completion_callback=self.complete_topic) + ]) -longhelp=""" -Print help for specified command or list of all commands. -""" + def _run(self, storage, bugdir, **params): + if params['topic'] == None: + if hasattr(self.ui, 'help'): + self.ui.help() + elif params['topic'] in libbe.command.commands(): + module = libbe.command.get_command(params['topic']) + Class = libbe.command.get_command_class(module,params['topic']) + c = Class() + print >> self.stdout, c.help().rstrip('\n') + elif params['topic'] in TOPICS: + print >> self.stdout, TOPICS[params['topic']].rstrip('\n') + else: + raise libbe.command.UserError( + '"%s" is neither a command nor topic' % params['topic']) + return 0 -def help(): - return get_parser().help_str() + longhelp + def _long_help(self): + return """ +Print help for specified command/topic or list of all commands. +""" -def complete(options, args, parser): - for option, value in cmdutil.option_value_pairs(options, parser): - if value == "--complete": - # no argument-options at the moment, so this is future-proofing - raise cmdutil.GetCompletions() - if "--complete" in args: - cmds = [command for command,module in cmdutil.iter_commands()] - raise cmdutil.GetCompletions(cmds) + def complete_topic(self, command, argument, fragment=None): + commands = libbe.command.util.complete_command() + topics = sorted(TOPICS.keys()) + return commands + topics |