From 6939471e485ccaece4f6fa0bcd8b9bd12396a32c Mon Sep 17 00:00:00 2001 From: Benex254 Date: Sun, 11 Aug 2024 21:57:11 +0300 Subject: [PATCH] feat(cli): add update app command --- fastanime/cli/__init__.py | 8 +------ fastanime/cli/app_updater.py | 9 ++++---- fastanime/cli/commands/update.py | 37 ++++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 11 deletions(-) create mode 100644 fastanime/cli/commands/update.py diff --git a/fastanime/cli/__init__.py b/fastanime/cli/__init__.py index 0680bb9..ccf602e 100644 --- a/fastanime/cli/__init__.py +++ b/fastanime/cli/__init__.py @@ -15,6 +15,7 @@ commands = { "downloads": "downloads.downloads", "cache": "cache.cache", "completions": "completions.completions", + "update": "update.update", } @@ -42,7 +43,6 @@ signal.signal(signal.SIGINT, handle_exit) @click.option("--log", help="Allow logging to stdout", is_flag=True) @click.option("--log-file", help="Allow logging to a file", is_flag=True) @click.option("--rich-traceback", help="Use rich to output tracebacks", is_flag=True) -@click.option("--update", help="Update fastanime to the latest version", is_flag=True) @click.option( "-p", "--provider", @@ -135,7 +135,6 @@ def run_cli( log, log_file, rich_traceback, - update, provider, server, format, @@ -192,11 +191,6 @@ def run_cli( from rich.traceback import install install() - if update and None: - from .app_updater import update_app - - update_app() - return if provider: ctx.obj.provider = provider diff --git a/fastanime/cli/app_updater.py b/fastanime/cli/app_updater.py index 48aa5b7..e0219e8 100644 --- a/fastanime/cli/app_updater.py +++ b/fastanime/cli/app_updater.py @@ -62,7 +62,7 @@ def update_app(): is_latest, release_json = check_for_updates() if is_latest: print("[green]App is up to date[/]") - return + return False, release_json tag_name = release_json["tag_name"] print("[cyan]Updating app to version %s[/]" % tag_name) @@ -76,7 +76,8 @@ def update_app(): print(f"Pulling latest changes from the repository via git: {shlex.join(args)}") if not GIT_EXECUTABLE: - return print("[red]Cannot find git please install it.[/]") + print("[red]Cannot find git please install it.[/]") + return False, release_json process = subprocess.run( args, @@ -99,6 +100,6 @@ def update_app(): ] process = subprocess.run(args) if process.returncode == 0: - return True + return True, release_json else: - return False + return False, release_json diff --git a/fastanime/cli/commands/update.py b/fastanime/cli/commands/update.py new file mode 100644 index 0000000..934c2fd --- /dev/null +++ b/fastanime/cli/commands/update.py @@ -0,0 +1,37 @@ +import click + + +@click.command(help="Helper command to update fastanime to latest") +@click.option("--check", "-c", help="Check for the latest release", is_flag=True) +def update( + check, +): + from rich.console import Console + from rich.markdown import Markdown + + from ..app_updater import check_for_updates, update_app + + def _print_release(release_data): + console = Console() + body = Markdown(release_data["body"]) + tag = github_release_data["tag_name"] + tag_title = release_data["name"] + github_page_url = release_data["html_url"] + console.print(f"Release Page: {github_page_url}") + console.print(f"Tag: {tag}") + console.print(f"Title: {tag_title}") + console.print(body) + + if check: + is_update, github_release_data = check_for_updates() + if is_update: + print( + "You are running an older version of fastanime please update to get the latest features" + ) + _print_release(github_release_data) + else: + print("You are running the latest version of fastanime") + _print_release(github_release_data) + else: + success, github_release_data = update_app() + _print_release(github_release_data)