Skip to content
Snippets Groups Projects
Commit 280652a2 authored by Seblu's avatar Seblu
Browse files

correctly handle ? and ! completion and execution

parent a5822e51
No related branches found
No related tags found
No related merge requests found
......@@ -120,19 +120,24 @@ class Cli(object):
def _exec_command(self, argv):
'''Execute command'''
self.printer.debug("argv: %s"%argv)
try:
if (argv[0][0] == "!"):
# handle ! in command name
if argv[0][0] == "!":
argv[0] = argv[0][1:]
if not len(argv[0]):
return
p = subprocess.Popen(argv, close_fds=True, shell=True)
p.wait()
ret = p.returncode
elif (argv[0] == "?"):
Command(["help"], self).call()
else:
Command(argv, self).call()
return
# handle ? in command name
if argv[0][0] == "?":
if len(argv[0]) > 1:
argv.insert(1, argv[0][1:])
argv[0] = "help"
# execute command
self.printer.debug("argv: %s"%argv)
Command(argv, self).call()
except cmdBadArgument as e:
if str(e):
self.printer.error("Bad argument: %s."%str(e))
......@@ -150,8 +155,7 @@ class Cli(object):
except EOFError:
self.printer.out("")
except Exception as e:
if cccli.debug:
raise
if cccli.debug: raise
self.printer.error("%s: %s"%(type(e), str(e)))
self.printer.warn("This is a not expected error, please report it!")
......@@ -160,7 +164,11 @@ class Cli(object):
comp = self.printer.completion
stripped = comp.get_buf()[:comp.get_begin() + 1].lstrip()
if texte == "" and stripped != "":
return None
return ()
if len(texte) > 0 and texte[0] == "!":
return ()
if len(texte) > 0 and texte[0] == "?":
texte = texte[1:]
return [ c for c in Command.list() + self.alias.keys() if c.startswith(texte) ]
class CliHandler(RpcHandler):
......
......@@ -259,3 +259,4 @@ class Completion(object):
self.compfunc = func
self.readline.set_completer(self._completer)
self.readline.parse_and_bind("tab: complete")
self.readline.set_completer_delims(" \t")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment