From d8938ee0338c0624290dffaa6e6b6969f550bb90 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Sat, 17 Jun 2023 07:05:58 -0700 Subject: [PATCH] aider: Added support for `--version` flag to display the version number. # Context: USER: should `aider --help` show the version now? ASSISTANT: Yes, with the changes you made, running `aider --help` should show the version information. However, the version will be displayed when you run `aider --version`. The `--help` output will include a line mentioning the `--version` flag, but it won't directly show the version number. USER: I ran this command: aider --version And got this output: Traceback (most recent call last): File "/Users/gauthier/Projects/aider/.venv/bin/aider", line 8, in sys.exit(main()) ^^^^^^ File "/Users/gauthier/Projects/aider/aider/main.py", line 32, in main parser = configargparse.ArgumentParser( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/gauthier/Projects/aider/.venv/lib/python3.11/site-packages/configargparse.py", line 433, in __init__ argparse.ArgumentParser.__init__(self, *args, **kwargs) TypeError: ArgumentParser.__init__() got an unexpected keyword argument 'version' ASSISTANT: I apologize for the confusion earlier. It seems I made a mistake. `configargparse` does not have a built-in `version` parameter like `argparse`. Instead, you can add a custom argument with the `--version` flag and handle it manually. Here's how you can modify your `aider/main.py` file: ```python aider/main.py <<<<<<< ORIGINAL parser = configargparse.ArgumentParser( description="aider is GPT powered coding in your terminal", add_config_file_help=True, default_config_files=default_config_files, config_file_parser_class=configargparse.YAMLConfigFileParser, auto_env_var_prefix="AIDER_", version=__version__, ) ======= parser = configargparse.ArgumentParser( description="aider is GPT powered coding in your terminal", add_config_file_help=True, default_config_files=default_config_files, config_file_parser_class=configargparse.YAMLConfigFileParser, auto_env_var_prefix="AIDER_", ) parser.add_argument( "--version", action="store_true", help="Show the version number and exit", ) >>>>>>> UPDATED ``` ```python aider/main.py <<<<<<< ORIGINAL args = parser.parse_args(args) ======= args, unknown_args = parser.parse_known_args(args) if args.version: print(f"aider version {__version__}") sys.exit(0) # Re-parse the arguments to include unknown_args args = parser.parse_args(args + unknown_args) ^C KeyboardInterrupt USER: can we add soemthing like this: parser.add_argument('-v', '--version', action='version', version='%(prog)s ' + __version__) ASSISTANT: I apologize for the confusion earlier. It turns out that `configargparse` does support the `version` action, similar to `argparse`. You can add the `--version` argument as you suggested. Here's how you can modify your `aider/main.py` file: ```python aider/main.py <<<<<<< ORIGINAL parser = configargparse.ArgumentParser( description="aider is GPT powered coding in your terminal", add_config_file_help=True, default_config_files=default_config_files, config_file_parser_class=configargparse.YAMLConfigFileParser, auto_env_var_prefix="AIDER_", version=__version__, ) ======= parser = configargparse.ArgumentParser( description="aider is GPT powered coding in your terminal", add_config_file_help=True, default_config_files=default_config_files, config_file_parser_class=configargparse.YAMLConfigFileParser, auto_env_var_prefix="AIDER_", ) parser.add_argument( "-v", "--version", action="version", version=f"%(prog)s {__version__}", help="Show the version number and exit" ) >>>>>>> UPDATED ``` Now, running `aider --version` or `aider -v` will display the version number as expected. --- aider/main.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/aider/main.py b/aider/main.py index cb055e14b..2593cb657 100644 --- a/aider/main.py +++ b/aider/main.py @@ -35,7 +35,10 @@ def main(args=None, input=None, output=None): default_config_files=default_config_files, config_file_parser_class=configargparse.YAMLConfigFileParser, auto_env_var_prefix="AIDER_", - version=__version__, + ) + + parser.add_argument( + "-v", "--version", action="version", version=f"%(prog)s {__version__}", help="Show the version number and exit" ) parser.add_argument(