various tweaks and fixes
This commit is contained in:
parent
ed7fe60a6d
commit
ed7d265b48
5 changed files with 524 additions and 212 deletions
46
shell.py
46
shell.py
|
@ -140,13 +140,25 @@ class Shell(object):
|
|||
conventionally called args or argv"""
|
||||
self.__commands[commandName] = command
|
||||
|
||||
def unRegisterCommand(self, commandName: str):
|
||||
"""Remove a command. May be useful for inheriting classes and the like."""
|
||||
del self.__commands[commandName]
|
||||
|
||||
def registerAlias(self, a: str, original: list):
|
||||
"""makes 'a' an alias for original.
|
||||
'a' must be one token, but original can be multiple."""
|
||||
self.__aliases[a] = original
|
||||
|
||||
def unRegisterAlias(self, commandName: str):
|
||||
"""Remove an alias. May be useful for inheriting classes and the like."""
|
||||
del self.__aliases[commandName]
|
||||
|
||||
def registerBatch(self, name: str, commands: list):
|
||||
self.__batches[name] = commands
|
||||
|
||||
def unRegisterBatch(self, commandName: str):
|
||||
"""Remove a command. May be useful for inheriting classes and the like."""
|
||||
del self.__batches[commandName]
|
||||
|
||||
def getAlias(self, a: str):
|
||||
if a in self.__aliases:
|
||||
|
@ -164,29 +176,39 @@ conventionally called args or argv"""
|
|||
"""Take a line of text and turn it into an argument list"""
|
||||
if instr == '':
|
||||
return []
|
||||
literalStr = list(instr)
|
||||
inQuotes = False
|
||||
ret = []
|
||||
argStart = 0
|
||||
c = 0
|
||||
l = 0
|
||||
while c < len(instr):
|
||||
if inQuotes:
|
||||
if instr[c] == '"':
|
||||
inQuotes = False
|
||||
ret.append(instr[argStart:c])
|
||||
argStart = c+1
|
||||
if instr[c-1] == '\\':
|
||||
del literalStr[l-1]
|
||||
l -= 1
|
||||
else:
|
||||
inQuotes = False
|
||||
del literalStr[l]
|
||||
l -= 1
|
||||
else:
|
||||
if instr[c] == '"':
|
||||
inQuotes = True
|
||||
if argStart != c:
|
||||
ret.append(instr[argStart:c])
|
||||
argStart = c+1
|
||||
if l > 0 and instr[c-1] == '\\':
|
||||
del literalStr[l-1]
|
||||
l -= 1
|
||||
else:
|
||||
inQuotes = True
|
||||
del literalStr[l]
|
||||
l -= 1
|
||||
elif instr[c] in ' \t\n':
|
||||
if argStart != c:
|
||||
ret.append(instr[argStart:c])
|
||||
argStart = c + 1
|
||||
if argStart != l:
|
||||
ret.append(''.join(literalStr[argStart:l]))
|
||||
argStart = l + 1
|
||||
c += 1
|
||||
if argStart != c:
|
||||
ret.append(instr[argStart:c])
|
||||
l += 1
|
||||
if argStart != l:
|
||||
ret.append(''.join(literalStr[argStart:l]))
|
||||
a = self.getAlias(ret[0])
|
||||
if a:
|
||||
ret = a + ret[1:]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue