diff options
Diffstat (limited to 'becommands/comment.py')
-rw-r--r-- | becommands/comment.py | 74 |
1 files changed, 54 insertions, 20 deletions
diff --git a/becommands/comment.py b/becommands/comment.py index 172f818..b15a06e 100644 --- a/becommands/comment.py +++ b/becommands/comment.py @@ -15,19 +15,19 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA """Add a comment to a bug""" -from libbe import cmdutil, bugdir, utility +from libbe import cmdutil, bugdir, settings_object, editor import os __desc__ = __doc__ -def execute(args): +def execute(args, test=False): """ >>> import time >>> bd = bugdir.simple_bug_dir() >>> os.chdir(bd.root) - >>> execute(["a", "This is a comment about a"]) + >>> execute(["a", "This is a comment about a"], test=True) >>> bd._clear_bugs() >>> bug = bd.bug_from_shortname("a") - >>> bug.load_comments() + >>> bug.load_comments(load_full=False) >>> comment = bug.comment_root[0] >>> print comment.body This is a comment about a @@ -36,31 +36,32 @@ def execute(args): True >>> comment.time <= int(time.time()) True - >>> comment.in_reply_to is None + >>> comment.in_reply_to is settings_object.EMPTY True >>> if 'EDITOR' in os.environ: ... del os.environ["EDITOR"] - >>> execute(["b"]) + >>> execute(["b"], test=True) Traceback (most recent call last): UserError: No comment supplied, and EDITOR not specified. >>> os.environ["EDITOR"] = "echo 'I like cheese' > " - >>> execute(["b"]) + >>> execute(["b"], test=True) >>> bd._clear_bugs() >>> bug = bd.bug_from_shortname("b") - >>> bug.load_comments() + >>> bug.load_comments(load_full=False) >>> comment = bug.comment_root[0] >>> print comment.body I like cheese <BLANKLINE> """ - options, args = get_parser().parse_args(args) + parser = get_parser() + options, args = parser.parse_args(args) + complete(options, args, parser) if len(args) == 0: - raise cmdutil.UserError("Please specify a bug or comment id.") + raise cmdutil.UsageError("Please specify a bug or comment id.") if len(args) > 2: - help() - raise cmdutil.UserError("Too many arguments.") + raise cmdutil.UsageError("Too many arguments.") shortname = args[0] if shortname.count(':') > 1: @@ -73,20 +74,20 @@ def execute(args): bugname = shortname is_reply = False - bd = bugdir.BugDir(from_disk=True) + bd = bugdir.BugDir(from_disk=True, manipulate_encodings=not test) bug = bd.bug_from_shortname(bugname) - bug.load_comments() + bug.load_comments(load_full=False) if is_reply: - parent = bug.comment_root.comment_from_shortname(shortname, bug_shortname=bugname) + parent = bug.comment_root.comment_from_shortname(shortname, + bug_shortname=bugname) else: parent = bug.comment_root if len(args) == 1: try: - body = utility.editor_string("Please enter your comment above") - except utility.CantFindEditor: - raise cmdutil.UserError( - "No comment supplied, and EDITOR not specified.") + body = editor.editor_string("Please enter your comment above") + except editor.CantFindEditor, e: + raise cmdutil.UserError, "No comment supplied, and EDITOR not specified." if body is None: raise cmdutil.UserError("No comment entered.") body = body.decode('utf-8') @@ -107,8 +108,41 @@ To add a comment to a bug, use the bug ID as the argument. To reply to another comment, specify the comment name (as shown in "be show" output). $EDITOR is used to launch an editor. If unspecified, no comment will be -created.) +created. """ def help(): return get_parser().help_str() + longhelp + +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() + for pos,value in enumerate(args): + if value == "--complete": + if pos == 0: # fist positional argument is a bug or comment id + if len(args) >= 2: + partial = args[1].split(':')[0] # take only bugid portion + else: + partial = "" + ids = [] + try: + bd = bugdir.BugDir(from_disk=True, + manipulate_encodings=False) + bugs = [] + for uuid in bd.list_uuids(): + if uuid.startswith(partial): + bug = bd.bug_from_uuid(uuid) + if bug.active == True: + bugs.append(bug) + for bug in bugs: + shortname = bd.bug_shortname(bug) + ids.append(shortname) + bug.load_comments(load_full=False) + for id,comment in bug.comment_shortnames(shortname): + ids.append(id) + except bugdir.NoBugDir: + pass + raise cmdutil.GetCompletions(ids) + raise cmdutil.GetCompletions() |