Skip to content

Commit b670143

Browse files
committed
Fix macro argument lexing
1 parent bf32a4d commit b670143

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/gptcmd/cli.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,9 @@ def _complete_from_key(d: Dict, text: str) -> List[str]:
193193
return [k for k, v in d.items() if k.startswith(text)]
194194

195195
@staticmethod
196-
def _shlex_path(path: str) -> List[str]:
197-
lexer = shlex.shlex(path, posix=True)
196+
def _lex_args(line: str) -> List[str]:
197+
"Lex a string into a list of shell-like arguments"
198+
lexer = shlex.shlex(line, posix=True)
198199
lexer.escape = ""
199200
lexer.whitespace_split = True
200201
return list(lexer)
@@ -365,7 +366,7 @@ def default(self, line: str) -> bool:
365366
) and name.endswith(self.config.SYSTEM_MACRO_SUFFIX)
366367
if not is_system_macro:
367368
try:
368-
args = shlex.split(arg, posix=True)
369+
args = self.__class__._lex_args(arg)
369370
except ValueError as e:
370371
print(f"Error parsing macro arguments: {e}")
371372
return False
@@ -1142,7 +1143,7 @@ def do_save(
11421143
Save all named threads to the specified json file. With no argument,
11431144
save to the most recently loaded/saved JSON file in this session.
11441145
"""
1145-
args = self.__class__._shlex_path(arg)
1146+
args = self.__class__._lex_args(arg)
11461147
if len(args) > 1:
11471148
print("Usage: save [path]")
11481149
return
@@ -1187,7 +1188,7 @@ def do_load(self, arg, _print_on_success=True):
11871188
print("Usage: load <path>\n")
11881189
return
11891190
try:
1190-
args = self.__class__._shlex_path(arg)
1191+
args = self.__class__._lex_args(arg)
11911192
except ValueError as e:
11921193
print(e)
11931194
return
@@ -1240,7 +1241,7 @@ def do_read(self, arg):
12401241
example: "read /path/to/prompt.txt system"
12411242
"""
12421243
try:
1243-
args = self.__class__._shlex_path(arg)
1244+
args = self.__class__._lex_args(arg)
12441245
except ValueError as e:
12451246
print(e)
12461247
return
@@ -1267,7 +1268,7 @@ def complete_read(self, text, line, begidx, endidx):
12671268
def do_write(self, arg):
12681269
"Write the contents of the last message to the specified file."
12691270
try:
1270-
args = self.__class__._shlex_path(arg)
1271+
args = self.__class__._lex_args(arg)
12711272
except ValueError as e:
12721273
print(e)
12731274
return
@@ -1298,7 +1299,7 @@ def do_transcribe(self, arg):
12981299
specified file.
12991300
"""
13001301
try:
1301-
args = self.__class__._shlex_path(arg)
1302+
args = self.__class__._lex_args(arg)
13021303
except ValueError as e:
13031304
print(e)
13041305
return
@@ -1346,7 +1347,7 @@ def _attachment_url_helper(
13461347
a = attachment_type(url=location)
13471348
else:
13481349
a = attachment_type.from_path(
1349-
self.__class__._shlex_path(location)[0]
1350+
self.__class__._lex_args(location)[0]
13501351
)
13511352
except (OSError, ValueError) as e:
13521353
print(e)

0 commit comments

Comments
 (0)