From 0e9e037c06d4a355944be9a04877e120698e367c Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Sat, 19 Aug 2023 07:16:37 -0700 Subject: [PATCH] aider: Change all the --foo/--no-foo switches to use the `parser.add_argument('--feature', action=argparse.BooleanOptionalAction)` convention. # Aider chat conversation: USER: change all the --foo/--no-foo switches to use the `parser.add_argument('--feature', action=argparse.BooleanOptionalAction)` convention ASSISTANT: To implement this change, we need to modify the `aider/main.py` file. We will replace all instances of `--foo` and `--no-foo` switches with the `parser.add_argument('--feature', action=argparse.BooleanOptionalAction)` convention. Here are the changes: ```python aider/main.py <<<<<<< HEAD output_group.add_argument( "--pretty", action="store_true", default=True, help="Enable pretty, colorized output (default: True)", ) output_group.add_argument( "--no-pretty", action="store_false", dest="pretty", help="Disable pretty, colorized output", ) output_group.add_argument( "--no-stream", action="store_false", dest="stream", default=True, help="Disable streaming responses", ) git_group.add_argument( "--no-git", action="store_false", dest="git", default=True, help="Do not look for a git repo", ) git_group.add_argument( "--auto-commits", action="store_true", dest="auto_commits", default=True, help="Enable auto commit of GPT changes (default: True)", ) git_group.add_argument( "--no-auto-commits", action="store_false", dest="auto_commits", help="Disable auto commit of GPT changes (implies --no-dirty-commits)", ) git_group.add_argument( "--dirty-commits", action="store_true", dest="dirty_commits", help="Enable commits when repo is found dirty", default=True, ) git_group.add_argument( "--no-dirty-commits", action="store_false", dest="dirty_commits", help="Disable commits when repo is found dirty", ) git_group.add_argument( "--dry-run", action="store_true", help="Perform a dry run without modifying files (default: False)", default=False, ) ======= output_group.add_argument( "--pretty", action=argparse.BooleanOptionalAction, default=True, help="Enable/disable pretty, colorized output (default: True)", ) output_group.add_argument( "--stream", action=argparse.BooleanOptionalAction, default=True, help="Enable/disable streaming responses (default: True)", ) git_group.add_argument( "--git", action=argparse.BooleanOptionalAction, default=True, help="Enable/disable looking for a git repo (default: True)", ) git_group.add_argument( "--auto-commits", action=argparse.BooleanOptionalAction, default=True, help="Enable/disable auto commit of GPT changes (default: True)", ) git_group.add_argument( "--dirty-commits", action=argparse.BooleanOptionalAction, default=True, help="Enable/disable commits when repo is found dirty (default: True)", ) git_group.add_argument( "--dry-run", action=argparse.BooleanOptionalAction, default=False, help="Enable/disable performing a dry run without modifying files (default: False)", ) >>>>>>> updated ``` Please note that the `argparse.BooleanOptionalAction` was introduced in Python 3.9. If you're using an older version of Python, you might need to upgrade or use a different approach. USER: InvalidEditBlock: edit failed! aider/main.py does not contain the *exact sequence* of HEAD lines you specified. Try again. DO NOT skip blank lines, comments, docstrings, etc! The HEAD block needs to be EXACTLY the same as the lines in aider/main.py with nothing missing! aider/main.py does not contain these 58 exact lines in a row: ``` output_group.add_argument( "--pretty", action="store_true", default=True, help="Enable pretty, colorized output (default: True)", ) output_group.add_argument( "--no-pretty", action="store_false", dest="pretty", help="Disable pretty, colorized output", ) output_group.add_argument( "--no-stream", action="store_false", dest="stream", default=True, help="Disable streaming responses", ) git_group.add_argument( "--no-git", action="store_false", dest="git", default=True, help="Do not look for a git repo", ) git_group.add_argument( "--auto-commits", action="store_true", dest="auto_commits", default=True, help="Enable auto commit of GPT changes (default: True)", ) git_group.add_argument( "--no-auto-commits", action="store_false", dest="auto_commits", help="Disable auto commit of GPT changes (implies --no-dirty-commits)", ) git_group.add_argument( "--dirty-commits", action="store_true", dest="dirty_commits", help="Enable commits when repo is found dirty", default=True, ) git_group.add_argument( "--no-dirty-commits", action="store_false", dest="dirty_commits", help="Disable commits when repo is found dirty", ) git_group.add_argument( "--dry-run", action="store_true", help="Perform a dry run without modifying files (default: False)", default=False, ) ``` ASSISTANT: I apologize for the confusion. It seems I made a mistake in grouping the changes. The arguments are not all together in the file, they are spread out in different argument groups. I will correct this and provide the changes in separate edit blocks for each argument group. Here are the corrected changes: ```python aider/main.py <<<<<<< HEAD output_group.add_argument( "--pretty", action="store_true", default=True, help="Enable pretty, colorized output (default: True)", ) output_group.add_argument( "--no-pretty", action="store_false", dest="pretty", help="Disable pretty, colorized output", ) output_group.add_argument( "--no-stream", action="store_false", dest="stream", default=True, help="Disable streaming responses", ) ======= output_group.add_argument( "--pretty", action=argparse.BooleanOptionalAction, default=True, help="Enable/disable pretty, colorized output (default: True)", ) output_group.add_argument( "--stream", action=argparse.BooleanOptionalAction, default=True, help="Enable/disable streaming responses (default: True)", ) >>>>>>> updated ``` ```python aider/main.py <<<<<<< HEAD git_group.add_argument( "--no-git", action="store_false", dest="git", default=True, help="Do not look for a git repo", ) git_group.add_argument( "--auto-commits", action="store_true", dest="auto_commits", default=True, help="Enable auto commit of GPT changes (default: True)", ) git_group.add_argument( "--no-auto-commits", action="store_false", dest="auto_commits", help="Disable auto commit of GPT changes (implies --no-dirty-commits)", ) git_group.add_argument( "--dirty-commits", action="store_true", dest="dirty_commits", help="Enable commits when repo is found dirty", default=True, ) git_group.add_argument( "--no-dirty-commits", action="store_false", dest="dirty_commits", help="Disable commits when repo is found dirty", ) git_group.add_argument( "--dry-run", action="store_true", help="Perform a dry run without modifying files (default: False)", default=False, ) ======= git_group.add_argument( "--git", action=argparse.BooleanOptionalAction, default=True, help="Enable/disable looking for a git repo (default: True)", ) git_group.add_argument( "--auto-commits", action=argparse.BooleanOptionalAction, default=True, help="Enable/disable auto commit of GPT changes (default: True)", ) git_group.add_argument( "--dirty-commits", action=argparse.BooleanOptionalAction, default=True, help="Enable/disable commits when repo is found dirty (default: True)", ) git_group.add_argument( "--dry-run", action=argparse.BooleanOptionalAction, default=False, help="Enable/disable performing a dry run without modifying files (default: False)", ) >>>>>>> updated ``` Please note that the `argparse.BooleanOptionalAction` was introduced in Python 3.9. If you're using an older version of Python, you might need to upgrade or use a different approach. --- aider/main.py | 50 ++++++++++++++------------------------------------ 1 file changed, 14 insertions(+), 36 deletions(-) diff --git a/aider/main.py b/aider/main.py index 540c19bfe..b0561ba77 100644 --- a/aider/main.py +++ b/aider/main.py @@ -232,22 +232,15 @@ def main(argv=None, input=None, output=None, force_git_root=None): ) output_group.add_argument( "--pretty", - action="store_true", + action=argparse.BooleanOptionalAction, default=True, - help="Enable pretty, colorized output (default: True)", + help="Enable/disable pretty, colorized output (default: True)", ) output_group.add_argument( - "--no-pretty", - action="store_false", - dest="pretty", - help="Disable pretty, colorized output", - ) - output_group.add_argument( - "--no-stream", - action="store_false", - dest="stream", + "--stream", + action=argparse.BooleanOptionalAction, default=True, - help="Disable streaming responses", + help="Enable/disable streaming responses (default: True)", ) output_group.add_argument( "--user-input-color", @@ -287,43 +280,28 @@ def main(argv=None, input=None, output=None, force_git_root=None): ########## git_group = parser.add_argument_group("Git Settings") git_group.add_argument( - "--no-git", - action="store_false", - dest="git", + "--git", + action=argparse.BooleanOptionalAction, default=True, - help="Do not look for a git repo", + help="Enable/disable looking for a git repo (default: True)", ) git_group.add_argument( "--auto-commits", - action="store_true", - dest="auto_commits", + action=argparse.BooleanOptionalAction, default=True, - help="Enable auto commit of GPT changes (default: True)", - ) - git_group.add_argument( - "--no-auto-commits", - action="store_false", - dest="auto_commits", - help="Disable auto commit of GPT changes (implies --no-dirty-commits)", + help="Enable/disable auto commit of GPT changes (default: True)", ) git_group.add_argument( "--dirty-commits", - action="store_true", - dest="dirty_commits", - help="Enable commits when repo is found dirty", + action=argparse.BooleanOptionalAction, default=True, - ) - git_group.add_argument( - "--no-dirty-commits", - action="store_false", - dest="dirty_commits", - help="Disable commits when repo is found dirty", + help="Enable/disable commits when repo is found dirty (default: True)", ) git_group.add_argument( "--dry-run", - action="store_true", - help="Perform a dry run without modifying files (default: False)", + action=argparse.BooleanOptionalAction, default=False, + help="Enable/disable performing a dry run without modifying files (default: False)", ) ##########