From a10b08e8de24bb3a8e6a2558d7c473304734af4c Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Wed, 12 Jul 2023 13:40:10 -0700 Subject: [PATCH] aider: Add --show-map option to print the repo map and then exit. # Aider chat conversation: USER: add --show-map which will just print the repomap and then exit ASSISTANT: To add the `--show-map` option, we need to modify the `aider/main.py` file. We will add a new argument to the argument parser and then use this argument to conditionally print the repo map and exit. Here are the changes: ```python aider/main.py <<<<<<< ORIGINAL ########## other_group = parser.add_argument_group("Other Settings") other_group.add_argument( "--version", action="version", version=f"%(prog)s {__version__}", help="Show the version number and exit", ) ======= ########## other_group = parser.add_argument_group("Other Settings") other_group.add_argument( "--show-map", action="store_true", help="Print the repo map and exit", default=False, ) other_group.add_argument( "--version", action="version", version=f"%(prog)s {__version__}", help="Show the version number and exit", ) >>>>>>> UPDATED ``` ```python aider/main.py <<<<<<< ORIGINAL coder = Coder.create( main_model, args.edit_format, io, ## fnames=args.files, pretty=args.pretty, show_diffs=args.show_diffs, auto_commits=args.auto_commits, dirty_commits=args.dirty_commits, dry_run=args.dry_run, map_tokens=args.map_tokens, verbose=args.verbose, assistant_output_color=args.assistant_output_color, code_theme=args.code_theme, stream=args.stream, use_git=args.git, ) ======= if args.show_map: repo_map = RepoMap(map_tokens=args.map_tokens, root=git_root, main_model=main_model, io=io, verbose=args.verbose) print(repo_map) sys.exit(0) else: coder = Coder.create( main_model, args.edit_format, io, ## fnames=args.files, pretty=args.pretty, show_diffs=args.show_diffs, auto_commits=args.auto_commits, dirty_commits=args.dirty_commits, dry_run=args.dry_run, map_tokens=args.map_tokens, verbose=args.verbose, assistant_output_color=args.assistant_output_color, code_theme=args.code_theme, stream=args.stream, use_git=args.git, ) >>>>>>> UPDATED ``` Please note that the `RepoMap` class is used to create the repo map. If the `--show-map` option is used, the repo map is printed and the program exits. If not, the program continues as before. --- aider/main.py | 47 +++++++++++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 18 deletions(-) diff --git a/aider/main.py b/aider/main.py index b85444c49..61857a772 100644 --- a/aider/main.py +++ b/aider/main.py @@ -244,6 +244,12 @@ def main(args=None, input=None, output=None): ########## other_group = parser.add_argument_group("Other Settings") + other_group.add_argument( + "--show-map", + action="store_true", + help="Print the repo map and exit", + default=False, + ) other_group.add_argument( "--version", action="version", @@ -363,24 +369,29 @@ def main(args=None, input=None, output=None): setattr(openai, mod_key, val) io.tool_output(f"Setting openai.{mod_key}={val}") - coder = Coder.create( - main_model, - args.edit_format, - io, - ## - fnames=args.files, - pretty=args.pretty, - show_diffs=args.show_diffs, - auto_commits=args.auto_commits, - dirty_commits=args.dirty_commits, - dry_run=args.dry_run, - map_tokens=args.map_tokens, - verbose=args.verbose, - assistant_output_color=args.assistant_output_color, - code_theme=args.code_theme, - stream=args.stream, - use_git=args.git, - ) + if args.show_map: + repo_map = RepoMap(map_tokens=args.map_tokens, root=git_root, main_model=main_model, io=io, verbose=args.verbose) + print(repo_map) + sys.exit(0) + else: + coder = Coder.create( + main_model, + args.edit_format, + io, + ## + fnames=args.files, + pretty=args.pretty, + show_diffs=args.show_diffs, + auto_commits=args.auto_commits, + dirty_commits=args.dirty_commits, + dry_run=args.dry_run, + map_tokens=args.map_tokens, + verbose=args.verbose, + assistant_output_color=args.assistant_output_color, + code_theme=args.code_theme, + stream=args.stream, + use_git=args.git, + ) if args.dirty_commits: coder.commit(ask=True, which="repo_files")