[CalendarServer-changes] [8456] CalendarServer/trunk/calendarserver/tools/shell.py
source_changes at macosforge.org
source_changes at macosforge.org
Thu Dec 15 15:02:14 PST 2011
Revision: 8456
http://trac.macosforge.org/projects/calendarserver/changeset/8456
Author: wsanchez at apple.com
Date: 2011-12-15 15:02:14 -0800 (Thu, 15 Dec 2011)
Log Message:
-----------
Fix logic for token completion. Add complete_help().
Modified Paths:
--------------
CalendarServer/trunk/calendarserver/tools/shell.py
Modified: CalendarServer/trunk/calendarserver/tools/shell.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/shell.py 2011-12-15 22:34:20 UTC (rev 8455)
+++ CalendarServer/trunk/calendarserver/tools/shell.py 2011-12-15 23:02:14 UTC (rev 8456)
@@ -19,6 +19,7 @@
Interactive shell for navigating the data store.
"""
+import string
import os
import sys
import tty
@@ -213,26 +214,27 @@
tokens = self.tokenize("".join(self.lineBuffer[:self.lineBufferIndex]))
if tokens:
- cmd = tokens.pop(0)
+ if len(tokens) == 1 and self.lineBuffer[-1] in string.whitespace:
+ word = ""
+ else:
+ word = tokens[-1]
+ cmd = tokens.pop(0)
else:
- cmd = ""
+ word = cmd = ""
- if tokens:
+ if cmd and (tokens or word == ""):
# Completing arguments
m = getattr(self, "complete_%s" % (cmd,), None)
if not m:
return
- completions = m(tokens)
+ completions = tuple(m(tokens))
+
+ log.msg("COMPLETIONS: %r" % (completions,))
else:
# Completing command name
- word = cmd
+ completions = self._complete_commands(cmd)
- completions = set()
- for name, m in self.commands():
- if name.startswith(word):
- completions.add(name[len(word):])
-
if len(completions) == 1:
for completion in completions:
break
@@ -333,6 +335,13 @@
if not hasattr(m, "hidden"):
yield (attr[4:], m)
+ def _complete_commands(self, word):
+ completions = set()
+ for name, m in self.commands():
+ if name.startswith(word):
+ completions.add(name[len(word):])
+ return completions
+
def cmd_help(self, tokens):
"""
Show help.
@@ -396,6 +405,14 @@
for info in sorted(result):
self.terminal.write(format % (info))
+ def complete_help(self, tokens):
+ if len(tokens) == 0:
+ return (name for name, method in self.commands())
+ elif len(tokens) == 1:
+ return self._complete_commands(tokens[0])
+ else:
+ return ()
+
def cmd_emulate(self, tokens):
"""
Emulate editor behavior.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20111215/36dd83a4/attachment.html>
More information about the calendarserver-changes
mailing list