aboutsummaryrefslogtreecommitdiffstats
path: root/libbe/command
diff options
context:
space:
mode:
authorW. Trevor King <wking@drexel.edu>2010-02-01 11:36:21 -0500
committerW. Trevor King <wking@drexel.edu>2010-02-01 11:36:21 -0500
commit0dd273f8605bc21589a51d3b046a231ff9df6fbb (patch)
treefefc1e6270f27b7c8ad8b4440535f43b92b7f8b0 /libbe/command
parent148379492d314c0eb98ee8559aea7a2fd0baaeb2 (diff)
downloadbugseverywhere-0dd273f8605bc21589a51d3b046a231ff9df6fbb.tar.gz
Fix command name output of `be --complete`.
By adding command_names option to libbe.command.commands. Previous versions of `be --complete` printed "import_xml", not "import-xml". Also fixed libbe.command.base's doctests, so test.py can run them.
Diffstat (limited to 'libbe/command')
-rw-r--r--libbe/command/base.py37
-rw-r--r--libbe/command/util.py2
2 files changed, 34 insertions, 5 deletions
diff --git a/libbe/command/base.py b/libbe/command/base.py
index 6df04db..6b1c050 100644
--- a/libbe/command/base.py
+++ b/libbe/command/base.py
@@ -72,10 +72,38 @@ def get_command_class(module=None, command_name=None):
raise UnknownCommand(command_name)
return cmd
-def commands():
+def modname_to_command_name(modname):
+ """Little hack to replicate
+ >>> import sys
+ >>> def real_modname_to_command_name(modname):
+ ... mod = libbe.util.plugin.import_by_name(
+ ... 'libbe.command.%s' % modname)
+ ... attrs = [getattr(mod, name) for name in dir(mod)]
+ ... commands = []
+ ... for attr_name in dir(mod):
+ ... attr = getattr(mod, attr_name)
+ ... try:
+ ... if issubclass(attr, Command):
+ ... commands.append(attr)
+ ... except TypeError, e:
+ ... pass
+ ... if len(commands) == 0:
+ ... raise Exception('No Command classes in %s' % dir(mod))
+ ... return commands[0].name
+ >>> real_modname_to_command_name('new')
+ 'new'
+ >>> real_modname_to_command_name('import_xml')
+ 'import-xml'
+ """
+ return modname.replace('_', '-')
+
+def commands(command_names=False):
for modname in libbe.util.plugin.modnames('libbe.command'):
if modname not in ['base', 'util']:
- yield modname
+ if command_names == False:
+ yield modname
+ else:
+ yield modname_to_command_name(modname)
class CommandInput (object):
def __init__(self, name, help=''):
@@ -393,9 +421,10 @@ class StringInputOutput (InputOutput):
>>> s.stdin.read()
'hello'
>>> s.stdin.read()
+ ''
>>> print >> s.stdout, 'goodbye'
>>> s.get_stdout()
- 'goodbye\n'
+ 'goodbye\\n'
>>> s.get_stdout()
''
@@ -406,7 +435,7 @@ class StringInputOutput (InputOutput):
u'hello'
>>> print >> s.stdout, u'goodbye'
>>> s.get_stdout()
- u'goodbye\n'
+ u'goodbye\\n'
"""
def __init__(self):
stdin = StringIO.StringIO()
diff --git a/libbe/command/util.py b/libbe/command/util.py
index 977b596..6e8e36c 100644
--- a/libbe/command/util.py
+++ b/libbe/command/util.py
@@ -32,7 +32,7 @@ def complete_command(command, argument, fragment=None):
command argument is not used.
"""
- return list(libbe.command.commands())
+ return list(libbe.command.commands(command_names=True))
def comp_path(fragment=None):
"""List possible path completions for fragment."""