Add support for multiple file arguments using --file

This commit is contained in:
Paul Gauthier (aider) 2024-07-28 20:58:46 -03:00
parent 7cf4db58d9
commit 28772ddc03
2 changed files with 11 additions and 7 deletions

View file

@ -31,6 +31,9 @@ def get_parser(default_config_files, git_root):
group.add_argument(
"files", metavar="FILE", nargs="*", help="files to edit with an LLM (optional)"
)
group.add_argument(
"--file", action="append", metavar="FILE", help="specify a file to edit (can be used multiple times)"
)
group.add_argument(
"--openai-api-key",
metavar="OPENAI_API_KEY",

View file

@ -372,10 +372,11 @@ def main(argv=None, input=None, output=None, force_git_root=None, return_coder=F
for fname in loaded_dotenvs:
io.tool_output(f"Loaded {fname}")
fnames = [str(Path(fn).resolve()) for fn in args.files]
if len(args.files) > 1:
all_files = args.files + (args.file or [])
fnames = [str(Path(fn).resolve()) for fn in all_files]
if len(all_files) > 1:
good = True
for fname in args.files:
for fname in all_files:
if Path(fname).is_dir():
io.tool_error(f"{fname} is a directory, not provided alone.")
good = False
@ -386,13 +387,13 @@ def main(argv=None, input=None, output=None, force_git_root=None, return_coder=F
return 1
git_dname = None
if len(args.files) == 1:
if Path(args.files[0]).is_dir():
if len(all_files) == 1:
if Path(all_files[0]).is_dir():
if args.git:
git_dname = str(Path(args.files[0]).resolve())
git_dname = str(Path(all_files[0]).resolve())
fnames = []
else:
io.tool_error(f"{args.files[0]} is a directory, but --no-git selected.")
io.tool_error(f"{all_files[0]} is a directory, but --no-git selected.")
return 1
# We can't know the git repo for sure until after parsing the args.