diff --git a/pybacker/__main__.py b/pybacker/__main__.py index 3fdbd6f..acf8fc9 100644 --- a/pybacker/__main__.py +++ b/pybacker/__main__.py @@ -6,11 +6,13 @@ from shutil import copytree, rmtree from tkinter import Tk, filedialog +from core_helpers.updates import check_updates from rich import print from rich.traceback import install -from .cli import check_updates, get_parsed_args -from .consts import DEBUG, EXIT_FAILURE, EXIT_SUCCESS +from .cli import get_parsed_args +from .consts import DEBUG, EXIT_FAILURE, EXIT_SUCCESS, GITHUB +from .consts import __version__ as VERSION def check_dir_list(dirs: list) -> bool: @@ -184,7 +186,7 @@ def cleanup_and_exit(exit_code: int, backup_dir: Path) -> None: def main(): args = get_parsed_args() - check_updates() + check_updates(GITHUB, VERSION) print("1. Creating backup directory...") backup_dir = create_backup_dir(output=args.output, base_path=args.path) diff --git a/pybacker/cli.py b/pybacker/cli.py index 85a5184..18066af 100644 --- a/pybacker/cli.py +++ b/pybacker/cli.py @@ -1,13 +1,11 @@ """Command-line interface for the project.""" -from argparse import ArgumentParser, Namespace +from argparse import Namespace from pathlib import Path -import requests -from rich import print -from rich_argparse_plus import RichHelpFormatterPlus +from core_helpers.cli import ArgparseColorThemes, setup_parser -from .consts import GITHUB, MAX_TIMEOUT, PACKAGE +from .consts import PACKAGE from .consts import __desc__ as DESC from .consts import __version__ as VERSION @@ -19,14 +17,13 @@ def get_parsed_args() -> Namespace: Returns: The parsed arguments as a Namespace object. """ - parser = ArgumentParser( - description=DESC, # Program description - formatter_class=RichHelpFormatterPlus, # Disable line wrapping - allow_abbrev=False, # Disable abbreviations - add_help=False, # Disable default help + parser, g_main = setup_parser( + PACKAGE, + DESC, + VERSION, + ArgparseColorThemes.DEFAULT, ) - g_main = parser.add_argument_group("Main Options") # Source path argument g_main.add_argument( "-p", @@ -61,40 +58,4 @@ def get_parsed_args() -> Namespace: help="The output directory for the backup. Default is [i]backup_.[/]", ) - g_misc = parser.add_argument_group("Miscellaneous Options") - # Help - g_misc.add_argument( - "-h", "--help", action="help", help="Show this help message and exit." - ) - # Version - g_misc.add_argument( - "-V", - "--version", - action="version", - help="Show version number and exit.", - version=f"[argparse.prog]{PACKAGE}[/] version [i]{VERSION}[/]", - ) - return parser.parse_args() - - -def check_updates() -> None: - """ - Check if there is a newer version of the script available in the GitHub repository. - """ - project = GITHUB.split("https://github.com/")[1] - repo_url = f"https://api.github.com/repos/{project}/releases/latest" - - try: - response = requests.get(repo_url, timeout=MAX_TIMEOUT) - response.raise_for_status() - - latest_version = response.json()["tag_name"] - if latest_version != VERSION: - print( - f"\n[yellow]Newer version of the script available: {latest_version}.\n" - "Please consider updating your version.[/yellow]" - ) - - except requests.exceptions.RequestException as e: - print(f"[red]ERROR[/]: Could not check for updates: {e}")