Use shlex for console parsing.

master
q3k 2012-05-02 16:25:58 +00:00
parent 052ef59e3f
commit fdcde7be8f
1 changed files with 3 additions and 2 deletions

View File

@ -1,5 +1,6 @@
import logic import logic
import sys import sys
import shlex
actions = { actions = {
"initialize": (logic.initialize, [], True), "initialize": (logic.initialize, [], True),
@ -19,7 +20,7 @@ def start():
sys.stdout.write("> ") sys.stdout.write("> ")
sys.stdout.flush() sys.stdout.flush()
line = raw_input().strip() line = raw_input().strip()
command = line.split()[0] command = shlex.split(line)[0]
if command == "quit": if command == "quit":
break break
@ -42,7 +43,7 @@ def start():
print "[e] Make up your mind." print "[e] Make up your mind."
continue continue
given_arguments = line.split()[1:] given_arguments = shlex.split(line)[1:]
if len(given_arguments) != len(arguments): if len(given_arguments) != len(arguments):
print "[e] Syntax: %s %s" % (command, " ".join([argument[0] for argument in arguments])) print "[e] Syntax: %s %s" % (command, " ".join([argument[0] for argument in arguments]))
continue continue