@@ -193,8 +193,9 @@ def _complete_from_key(d: Dict, text: str) -> List[str]:
193
193
return [k for k , v in d .items () if k .startswith (text )]
194
194
195
195
@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 )
198
199
lexer .escape = ""
199
200
lexer .whitespace_split = True
200
201
return list (lexer )
@@ -365,7 +366,7 @@ def default(self, line: str) -> bool:
365
366
) and name .endswith (self .config .SYSTEM_MACRO_SUFFIX )
366
367
if not is_system_macro :
367
368
try :
368
- args = shlex . split (arg , posix = True )
369
+ args = self . __class__ . _lex_args (arg )
369
370
except ValueError as e :
370
371
print (f"Error parsing macro arguments: { e } " )
371
372
return False
@@ -1142,7 +1143,7 @@ def do_save(
1142
1143
Save all named threads to the specified json file. With no argument,
1143
1144
save to the most recently loaded/saved JSON file in this session.
1144
1145
"""
1145
- args = self .__class__ ._shlex_path (arg )
1146
+ args = self .__class__ ._lex_args (arg )
1146
1147
if len (args ) > 1 :
1147
1148
print ("Usage: save [path]" )
1148
1149
return
@@ -1187,7 +1188,7 @@ def do_load(self, arg, _print_on_success=True):
1187
1188
print ("Usage: load <path>\n " )
1188
1189
return
1189
1190
try :
1190
- args = self .__class__ ._shlex_path (arg )
1191
+ args = self .__class__ ._lex_args (arg )
1191
1192
except ValueError as e :
1192
1193
print (e )
1193
1194
return
@@ -1240,7 +1241,7 @@ def do_read(self, arg):
1240
1241
example: "read /path/to/prompt.txt system"
1241
1242
"""
1242
1243
try :
1243
- args = self .__class__ ._shlex_path (arg )
1244
+ args = self .__class__ ._lex_args (arg )
1244
1245
except ValueError as e :
1245
1246
print (e )
1246
1247
return
@@ -1267,7 +1268,7 @@ def complete_read(self, text, line, begidx, endidx):
1267
1268
def do_write (self , arg ):
1268
1269
"Write the contents of the last message to the specified file."
1269
1270
try :
1270
- args = self .__class__ ._shlex_path (arg )
1271
+ args = self .__class__ ._lex_args (arg )
1271
1272
except ValueError as e :
1272
1273
print (e )
1273
1274
return
@@ -1298,7 +1299,7 @@ def do_transcribe(self, arg):
1298
1299
specified file.
1299
1300
"""
1300
1301
try :
1301
- args = self .__class__ ._shlex_path (arg )
1302
+ args = self .__class__ ._lex_args (arg )
1302
1303
except ValueError as e :
1303
1304
print (e )
1304
1305
return
@@ -1346,7 +1347,7 @@ def _attachment_url_helper(
1346
1347
a = attachment_type (url = location )
1347
1348
else :
1348
1349
a = attachment_type .from_path (
1349
- self .__class__ ._shlex_path (location )[0 ]
1350
+ self .__class__ ._lex_args (location )[0 ]
1350
1351
)
1351
1352
except (OSError , ValueError ) as e :
1352
1353
print (e )
0 commit comments