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.
This commit is contained in:
Paul Gauthier 2023-07-12 13:40:10 -07:00
parent e3aa9db5a2
commit a10b08e8de

View file

@ -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")