From ac9160ae5407c4450e946e561e98bce5291e8adf Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Thu, 19 Oct 2023 20:18:02 -0700 Subject: [PATCH] aider: Add --encoding argument and pass it to `InputOutput`. # Aider chat conversation: USER: add --encoding and pass it to `InputOutput` ASSISTANT: To add the `--encoding` argument and pass it to `InputOutput`, we need to modify the `aider/main.py` file. Here are the steps: 1. Add a new argument `--encoding` to the `argparse.ArgumentParser` in the `main` function. 2. Pass the `args.encoding` to the `InputOutput` class instantiation. Here are the changes: ```python aider/main.py <<<<<<< HEAD ########## 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.add_argument( "--apply", metavar="FILE", help="Apply the changes from the given file instead of running the chat (debug)", ) other_group.add_argument( "--yes", action="store_true", help="Always say yes to every confirmation", default=None, ) other_group.add_argument( "-v", "--verbose", action="store_true", help="Enable verbose output", default=False, ) other_group.add_argument( "--show-repo-map", action="store_true", help="Print the repo map and exit (debug)", default=False, ) other_group.add_argument( "--message", "--msg", "-m", metavar="COMMAND", help="Specify a single message to send GPT, process reply then exit (disables chat mode)", ) other_group.add_argument( "-c", "--config", is_config_file=True, metavar="CONFIG_FILE", help=( "Specify the config file (default: search for .aider.conf.yml in git root, cwd" " or home directory)" ), ) args = parser.parse_args(argv) ======= ########## 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.add_argument( "--apply", metavar="FILE", help="Apply the changes from the given file instead of running the chat (debug)", ) other_group.add_argument( "--yes", action="store_true", help="Always say yes to every confirmation", default=None, ) other_group.add_argument( "-v", "--verbose", action="store_true", help="Enable verbose output", default=False, ) other_group.add_argument( "--show-repo-map", action="store_true", help="Print the repo map and exit (debug)", default=False, ) other_group.add_argument( "--message", "--msg", "-m", metavar="COMMAND", help="Specify a single message to send GPT, process reply then exit (disables chat mode)", ) other_group.add_argument( "--encoding", default="utf-8", help="Specify the encoding for input and output (default: utf-8)", ) other_group.add_argument( "-c", "--config", is_config_file=True, metavar="CONFIG_FILE", help=( "Specify the config file (default: search for .aider.conf.yml in git root, cwd" " or home directory)" ), ) args = parser.parse_args(argv) >>>>>>> updated ``` ```python aider/main.py <<<<<<< HEAD io = InputOutput( args.pretty, args.yes, args.input_history_file, args.chat_history_file, input=input, output=output, user_input_color=args.user_input_color, tool_output_color=args.tool_output_color, tool_error_color=args.tool_error_color, dry_run=args.dry_run, ) ======= io = InputOutput( args.pretty, args.yes, args.input_history_file, args.chat_history_file, input=input, output=output, user_input_color=args.user_input_color, tool_output_color=args.tool_output_color, tool_error_color=args.tool_error_color, dry_run=args.dry_run, encoding=args.encoding, ) >>>>>>> updated ``` Please note that the `InputOutput` class should be able to handle the `encoding` argument. If it's not the case, we need to modify the `InputOutput` class as well. --- aider/main.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/aider/main.py b/aider/main.py index 9b3b2597b..b0ebf5075 100644 --- a/aider/main.py +++ b/aider/main.py @@ -378,6 +378,11 @@ def main(argv=None, input=None, output=None, force_git_root=None): metavar="COMMAND", help="Specify a single message to send GPT, process reply then exit (disables chat mode)", ) + other_group.add_argument( + "--encoding", + default="utf-8", + help="Specify the encoding for input and output (default: utf-8)", + ) other_group.add_argument( "-c", "--config", @@ -414,6 +419,7 @@ def main(argv=None, input=None, output=None, force_git_root=None): tool_output_color=args.tool_output_color, tool_error_color=args.tool_error_color, dry_run=args.dry_run, + encoding=args.encoding, ) fnames = [str(Path(fn).resolve()) for fn in args.files]