diff options
-rw-r--r-- | becommands/show.py | 40 | ||||
-rw-r--r-- | libbe/cmdutil.py | 14 |
2 files changed, 42 insertions, 12 deletions
diff --git a/becommands/show.py b/becommands/show.py index ff434ab..dfaece1 100644 --- a/becommands/show.py +++ b/becommands/show.py @@ -53,27 +53,47 @@ def execute(args, test=False): parser = get_parser() options, args = parser.parse_args(args) cmdutil.default_complete(options, args, parser, - bugid_args={0: lambda bug : bug.active==True}) + bugid_args={-1: lambda bug : bug.active==True}) if len(args) == 0: raise cmdutil.UsageError bd = bugdir.BugDir(from_disk=True, manipulate_encodings=not test) - for bugid in args: - bug = bd.bug_from_shortname(bugid) - if options.dumpXML: - print bug.xml(show_comments=True) + for shortname in args: + if shortname.count(':') > 1: + raise cmdutil.UserError("Invalid id '%s'." % shortname) + elif shortname.count(':') == 1: + # Split shortname generated by Comment.comment_shortnames() + bugname = shortname.split(':')[0] + is_comment = True else: - print bug.string(show_comments=True) - if bugid != args[-1]: - print "" # add a blank line between bugs + bugname = shortname + is_comment = False + bug = bd.bug_from_shortname(bugname) + if is_comment == False: + if options.dumpXML: + print bug.xml(show_comments=True) + else: + print bug.string(show_comments=True) + else: + comment = bug.comment_root.comment_from_shortname( + shortname, bug_shortname=bugname) + if options.dumpXML: + print comment.xml(shortname=shortname) + else: + print comment.string(shortname=shortname) + if shortname != args[-1] and options.dumpXML == False: + print "" # add a blank line between bugs/comments def get_parser(): - parser = cmdutil.CmdOptionParser("be show [options] BUG-ID [BUG-ID ...]") + parser = cmdutil.CmdOptionParser("be show [options] ID [ID ...]") parser.add_option("-x", "--xml", action="store_true", dest='dumpXML', help="Dump as XML") return parser longhelp=""" -Show all information about a bug. +Show all information about the bugs or comments whose IDs are given. + +It's probably not a good idea to mix bug and comment IDs in a single +call, but you're free to do so if you like. """ def help(): diff --git a/libbe/cmdutil.py b/libbe/cmdutil.py index edc6442..0dd8ad0 100644 --- a/libbe/cmdutil.py +++ b/libbe/cmdutil.py @@ -141,7 +141,7 @@ def option_value_pairs(options, parser): def default_complete(options, args, parser, bugid_args={}): """ - A dud complete implementation for becommands to that the + A dud complete implementation for becommands so that the --complete argument doesn't cause any problems. Use this until you've set up a command-specific complete function. @@ -149,15 +149,25 @@ def default_complete(options, args, parser, bugid_args={}): arguments taking bug shortnames and the values are functions for filtering, since that's a common enough operation. e.g. for "be open [options] BUGID" - bugid_args = {0: lambda bug : bug.active == False} + bugid_args = {0: lambda bug : bug.active == False} + A positional argument of -1 specifies all remaining arguments + (e.g in the case of "be show BUGID BUGID ..."). """ for option,value in option_value_pairs(options, parser): if value == "--complete": raise cmdutil.GetCompletions() + if len(bugid_args.keys()) > 0: + max_pos_arg = max(bugid_args.keys()) + else: + max_pos_arg = -1 for pos,value in enumerate(args): if value == "--complete": + filter = None if pos in bugid_args: filter = bugid_args[pos] + if pos > max_pos_arg and -1 in bugid_args: + filter = bugid_args[-1] + if filter != None: bugshortnames = [] try: bd = bugdir.BugDir(from_disk=True, |