provide automagic command line splitting with quote support
This commit is contained in:
parent
88051c2d26
commit
df5f06f695
@ -2,29 +2,98 @@ from .ConsoleApplication import ConsoleApplication
|
||||
|
||||
class REPLApplication (ConsoleApplication):
|
||||
|
||||
def split_with_quotes(self, value : str):
|
||||
|
||||
escaping = False
|
||||
in_quote = 0
|
||||
next = ""
|
||||
retval = [ ]
|
||||
quote_types = [ ]
|
||||
|
||||
for i in range(0, len(value)):
|
||||
if value[i] == "\"" and not escaping:
|
||||
if in_quote == 0:
|
||||
in_quote = 1
|
||||
continue
|
||||
elif in_quote == 1:
|
||||
in_quote = 0
|
||||
|
||||
quote_types.append(1)
|
||||
retval.append(next)
|
||||
next = ""
|
||||
continue
|
||||
|
||||
elif value[i] == "'" and not escaping:
|
||||
if in_quote == 0:
|
||||
in_quote = 2
|
||||
continue
|
||||
elif in_quote == 2:
|
||||
in_quote = 0
|
||||
|
||||
quote_types.append(2)
|
||||
retval.append(next)
|
||||
next = ""
|
||||
continue
|
||||
|
||||
elif value[i] == "`" and not escaping:
|
||||
if in_quote == 0:
|
||||
in_quote = 3
|
||||
continue
|
||||
elif in_quote == 3:
|
||||
in_quote = 0
|
||||
|
||||
quote_types.append(3)
|
||||
retval.append(next)
|
||||
next = ""
|
||||
continue
|
||||
|
||||
elif value[i] == "\\" and not escaping:
|
||||
escaping = True
|
||||
continue
|
||||
|
||||
elif value[i] == " " and in_quote == 0:
|
||||
if not next == "":
|
||||
quote_types.append(None)
|
||||
retval.append(next)
|
||||
|
||||
next = ""
|
||||
escaping = False
|
||||
continue
|
||||
|
||||
next += value[i]
|
||||
escaping = False
|
||||
|
||||
if not next == "":
|
||||
quote_types.append(None)
|
||||
retval.append(next)
|
||||
next = ""
|
||||
|
||||
return (retval, quote_types)
|
||||
|
||||
def _start_internal(self):
|
||||
|
||||
while (True):
|
||||
# print ("open instance attribute relationship close")
|
||||
inp = input(self.get_prompt())
|
||||
input_str = input(self.get_prompt())
|
||||
(inp, quotes) = self.split_with_quotes(input_str)
|
||||
|
||||
if inp == "clear":
|
||||
if inp[0] == "clear":
|
||||
self.clear()
|
||||
continue
|
||||
|
||||
elif inp == "exit":
|
||||
elif inp[0] == "exit":
|
||||
break
|
||||
|
||||
elif inp == "help":
|
||||
elif inp[0] == "help":
|
||||
|
||||
continue
|
||||
|
||||
self.process_input(inp)
|
||||
self.process_input(inp, quotes)
|
||||
|
||||
exit(0)
|
||||
|
||||
def get_prompt(self):
|
||||
return "> "
|
||||
|
||||
def process_input(self, value):
|
||||
def process_input(self, value, quotes):
|
||||
pass
|
||||
Loading…
x
Reference in New Issue
Block a user