Skip to content

Commit a49b76b

Browse files
committed
Small update to version 2.0.0 to correctly handle unquoted Windows paths
1 parent 9f47436 commit a49b76b

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/gptcmd/cli.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
)
3939

4040

41-
__version__ = "2.0.0"
41+
__version__ = "2.0.1"
4242

4343

4444
def input_with_handling(_input: Callable) -> Callable:
@@ -168,6 +168,13 @@ def _confirm(prompt: str) -> bool:
168168
def _complete_from_key(d: Dict, text: str) -> List[str]:
169169
return [k for k, v in d.items() if k.startswith(text)]
170170

171+
@staticmethod
172+
def _shlex_path(path: str) -> List[str]:
173+
lexer = shlex.shlex(path, posix=True)
174+
lexer.escape = ""
175+
lexer.whitespace_split = True
176+
return list(lexer)
177+
171178
KNOWN_ROLES = tuple(MessageRole)
172179

173180
@classmethod
@@ -889,7 +896,7 @@ def do_save(self, arg):
889896
Save all named threads to the specified json file. With no argument,
890897
save to the most recently loaded/saved JSON file in this session.
891898
"""
892-
args = shlex.split(arg)
899+
args = self.__class__._shlex_path(arg)
893900
if len(args) > 1:
894901
print("Usage: save [path]")
895902
return
@@ -929,7 +936,7 @@ def do_load(self, arg, _print_on_success=True):
929936
print("Usage: load <path>\n")
930937
return
931938
try:
932-
args = shlex.split(arg)
939+
args = self.__class__._shlex_path(arg)
933940
except ValueError as e:
934941
print(e)
935942
return
@@ -983,7 +990,7 @@ def do_read(self, arg):
983990
example: "read /path/to/prompt.txt system"
984991
"""
985992
try:
986-
args = shlex.split(arg)
993+
args = self.__class__._shlex_path(arg)
987994
except ValueError as e:
988995
print(e)
989996
return
@@ -1010,7 +1017,7 @@ def complete_read(self, text, line, begidx, endidx):
10101017
def do_write(self, arg):
10111018
"Write the contents of the last message to the specified file."
10121019
try:
1013-
args = shlex.split(arg)
1020+
args = self.__class__._shlex_path(arg)
10141021
except ValueError as e:
10151022
print(e)
10161023
return
@@ -1041,7 +1048,7 @@ def do_transcribe(self, arg):
10411048
specified file.
10421049
"""
10431050
try:
1044-
args = shlex.split(arg)
1051+
args = self.__class__._shlex_path(arg)
10451052
except ValueError as e:
10461053
print(e)
10471054
return
@@ -1083,7 +1090,7 @@ def do_image(self, arg):
10831090
img = Image(url=location)
10841091
else:
10851092
try:
1086-
img = Image.from_path(shlex.split(location)[0])
1093+
img = Image.from_path(self.__class__._shlex_path(location)[0])
10871094
except (OSError, FileNotFoundError, ValueError) as e:
10881095
print(e)
10891096
return

0 commit comments

Comments
 (0)