diff --git a/aider/main.py b/aider/main.py index db0d986e2..086fbaccd 100644 --- a/aider/main.py +++ b/aider/main.py @@ -353,6 +353,12 @@ def main(argv=None, input=None, output=None, force_git_root=None): version=f"%(prog)s {__version__}", help="Show the version number and exit", ) + other_group.add_argument( + "--check-update", + action="store_true", + help="Check for updates and return status in the exit code", + default=False, + ) other_group.add_argument( "--apply", metavar="FILE", @@ -472,6 +478,10 @@ def main(argv=None, input=None, output=None, force_git_root=None): check_version(io.tool_error) + if args.check_update: + update_available = check_version(lambda msg: None) + sys.exit(0 if not update_available else 1) + if "VSCODE_GIT_IPC_HANDLE" in os.environ: args.pretty = False io.tool_output("VSCode terminal detected, pretty output has been disabled.") diff --git a/aider/versioncheck.py b/aider/versioncheck.py index 3c4ff2811..59a83f79c 100644 --- a/aider/versioncheck.py +++ b/aider/versioncheck.py @@ -13,14 +13,17 @@ def check_version(print_cmd): latest_version = data["info"]["version"] current_version = aider.__version__ - if packaging.version.parse(latest_version) <= packaging.version.parse(current_version): - return + is_update_available = packaging.version.parse(latest_version) > packaging.version.parse(current_version) - print_cmd(f"Newer version v{latest_version} is available. To upgrade, run:") - py = sys.executable - print_cmd(f"{py} -m pip install --upgrade aider-chat") + if is_update_available: + print_cmd(f"Newer version v{latest_version} is available. To upgrade, run:") + py = sys.executable + print_cmd(f"{py} -m pip install --upgrade aider-chat") + + return is_update_available except Exception as err: print_cmd(f"Error checking pypi for new version: {err}") + return False if __name__ == "__main__":