summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Van Brunt <kmvanbrunt@gmail.com>2018-03-16 22:17:52 -0400
committerKevin Van Brunt <kmvanbrunt@gmail.com>2018-03-16 22:17:52 -0400
commit24fdbbce8a7bb0df3b12fc91cb53a591777f9fb0 (patch)
treeb516a76aa6f89c3d93a83999c6952bee2cf89486
parentf68023a219e4e5b0997e28d7cc4f46eb05011665 (diff)
downloadcmd2-git-24fdbbce8a7bb0df3b12fc91cb53a591777f9fb0.tar.gz
Changing how commands are parsed if default_to_shell is True
-rwxr-xr-xcmd2.py13
-rw-r--r--tests/test_completion.py9
2 files changed, 17 insertions, 5 deletions
diff --git a/cmd2.py b/cmd2.py
index 28e22c45..d2f26166 100755
--- a/cmd2.py
+++ b/cmd2.py
@@ -1578,8 +1578,17 @@ class Cmd(cmd.Cmd):
break
i, n = 0, len(line)
- while i < n and line[i] in self.identchars:
- i += 1
+
+ # If we are allowing shell commands, then allow any character in the command
+ if self.default_to_shell:
+ while i < n and line[i] != ' ':
+ i += 1
+
+ # Otherwise only allow those in identchars
+ else:
+ while i < n and line[i] in self.identchars:
+ i += 1
+
command, arg = line[:i], line[i:].strip()
return command, arg, line
diff --git a/tests/test_completion.py b/tests/test_completion.py
index 78d045d7..7f9a6db0 100644
--- a/tests/test_completion.py
+++ b/tests/test_completion.py
@@ -311,15 +311,18 @@ def test_path_completion_nomatch(request):
assert path_complete(text, line, begidx, endidx) == []
-@pytest.mark.skipif(sys.platform == 'win32',
- reason="cmd command parsing only supports ascii characters and digits as part of a command name")
+
def test_default_to_shell_completion(cmd2_app, request):
cmd2_app.default_to_shell = True
test_dir = os.path.dirname(request.module.__file__)
text = 'c'
path = os.path.join(test_dir, text)
- command = 'egrep'
+
+ if sys.platform == "win32":
+ command = 'calc.exe'
+ else:
+ command = 'egrep'
# Make sure the command is on the testing system
assert command in cmd2.Cmd._get_exes_in_path(command)