Skip to content

Commit

Permalink
Small update to version 2.0.0 to correctly handle unquoted Windows paths
Browse files Browse the repository at this point in the history
  • Loading branch information
codeofdusk committed Nov 29, 2024
1 parent 9f47436 commit a49b76b
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/gptcmd/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
)


__version__ = "2.0.0"
__version__ = "2.0.1"


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

@staticmethod
def _shlex_path(path: str) -> List[str]:
lexer = shlex.shlex(path, posix=True)
lexer.escape = ""
lexer.whitespace_split = True
return list(lexer)

KNOWN_ROLES = tuple(MessageRole)

@classmethod
Expand Down Expand Up @@ -889,7 +896,7 @@ def do_save(self, arg):
Save all named threads to the specified json file. With no argument,
save to the most recently loaded/saved JSON file in this session.
"""
args = shlex.split(arg)
args = self.__class__._shlex_path(arg)
if len(args) > 1:
print("Usage: save [path]")
return
Expand Down Expand Up @@ -929,7 +936,7 @@ def do_load(self, arg, _print_on_success=True):
print("Usage: load <path>\n")
return
try:
args = shlex.split(arg)
args = self.__class__._shlex_path(arg)
except ValueError as e:
print(e)
return
Expand Down Expand Up @@ -983,7 +990,7 @@ def do_read(self, arg):
example: "read /path/to/prompt.txt system"
"""
try:
args = shlex.split(arg)
args = self.__class__._shlex_path(arg)
except ValueError as e:
print(e)
return
Expand All @@ -1010,7 +1017,7 @@ def complete_read(self, text, line, begidx, endidx):
def do_write(self, arg):
"Write the contents of the last message to the specified file."
try:
args = shlex.split(arg)
args = self.__class__._shlex_path(arg)
except ValueError as e:
print(e)
return
Expand Down Expand Up @@ -1041,7 +1048,7 @@ def do_transcribe(self, arg):
specified file.
"""
try:
args = shlex.split(arg)
args = self.__class__._shlex_path(arg)
except ValueError as e:
print(e)
return
Expand Down Expand Up @@ -1083,7 +1090,7 @@ def do_image(self, arg):
img = Image(url=location)
else:
try:
img = Image.from_path(shlex.split(location)[0])
img = Image.from_path(self.__class__._shlex_path(location)[0])
except (OSError, FileNotFoundError, ValueError) as e:
print(e)
return
Expand Down

0 comments on commit a49b76b

Please sign in to comment.