Added quote support for shell.py, so spaces can be put in single arguments
This commit is contained in:
parent
e96bdfaead
commit
9055d8b257
2 changed files with 47 additions and 13 deletions
31
shell.py
31
shell.py
|
@ -20,7 +20,7 @@
|
|||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
# MA 02110-1301, USA.
|
||||
#
|
||||
# Ver. 0.1.0028
|
||||
# Ver. 0.1.0029
|
||||
|
||||
|
||||
import types as _types
|
||||
|
@ -137,6 +137,7 @@ class Shell(object):
|
|||
else:
|
||||
self.handleUnknownCommand(command)
|
||||
self.update()
|
||||
self.__exit = False
|
||||
|
||||
def man(self, args):
|
||||
help(self.__commands[args[0]])
|
||||
|
@ -164,10 +165,32 @@ conventionally called args or argv"""
|
|||
# Beyond this point are functions that are called within the main loop.
|
||||
def scanInput(self):
|
||||
"""Parses input. Override this for custom input parsing, or input source."""
|
||||
ret = input()
|
||||
if ret == '':
|
||||
instr = input()
|
||||
if instr == '':
|
||||
return []
|
||||
ret = ret.split()
|
||||
inQuotes = False
|
||||
ret = []
|
||||
argStart = 0
|
||||
c = 0
|
||||
while c < len(instr):
|
||||
if inQuotes:
|
||||
if instr[c] == '"':
|
||||
inQuotes = False
|
||||
ret.append(instr[argStart:c])
|
||||
argStart = c+1
|
||||
else:
|
||||
if instr[c] == '"':
|
||||
inQuotes = True
|
||||
if argStart != c:
|
||||
ret.append(instr[argStart:c])
|
||||
argStart = c+1
|
||||
elif instr[c] in ' \t\n':
|
||||
if argStart != c:
|
||||
ret.append(instr[argStart:c])
|
||||
argStart = c + 1
|
||||
c += 1
|
||||
if argStart != c:
|
||||
ret.append(instr[argStart:c])
|
||||
a = self.getAlias(ret[0])
|
||||
if a:
|
||||
ret = a[:] + ret[1:]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue