Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions app/cli.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import logging
import platform
import sys

import click
import requests

from app.commands import check, download, progress, setup, verify
from app.commands import check, download, progress, setup, update, verify
from app.commands.version import version
from app.utils.click import ClickColor, CliContextKey, warn
from app.utils.version import Version
Expand Down Expand Up @@ -43,14 +44,20 @@ def cli(ctx, verbose) -> None:
fg=ClickColor.BRIGHT_RED,
)
)
warn("We strongly recommend upgrading your app.")
warn(
f"Follow the update guide here: {click.style('https://git-mastery.github.io/app/update', bold=True)}"
)
# Auto-update only supported on macOS
# TODO: Add support for other platforms
if platform.system().lower() == "darwin":
warn("Attempting automatic update...")
ctx.invoke(update)
else:
warn("We strongly recommend upgrading your app.")
warn(
f"Follow the update guide here: {click.style('https://git-mastery.github.io/app/update', bold=True)}"
)


def start() -> None:
commands = [check, download, progress, setup, verify, version]
commands = [check, download, progress, setup, update, verify, version]
for command in commands:
cli.add_command(command)
cli(obj={})
3 changes: 2 additions & 1 deletion app/commands/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
__all__ = ["check", "download", "progress", "setup", "verify", "version"]
__all__ = ["check", "download", "progress", "setup", "update", "verify", "version"]

from .check import check
from .download import download
from .progress.progress import progress
from .setup_folder import setup
from .update import update
from .verify import verify
from .version import version
42 changes: 42 additions & 0 deletions app/commands/update.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import logging
import platform
import subprocess

import click

from app.utils.click import info, success, warn

logger = logging.getLogger(__name__)


def is_macos() -> bool:
return platform.system().lower() == "darwin"


def run_brew_update() -> bool:
"""Updates Git-Mastery via Homebrew for macOS."""
try:
command = ["sh", "-c", "brew update && brew upgrade gitmastery"]
info(f"Running: {click.style(' '.join(command), bold=True)}")
result = subprocess.run(command)
return result.returncode == 0
except Exception as e:
logger.error(f"Failed to run update command: {e}")
return False


@click.command()
def update() -> None:
"""Update Git-Mastery to the latest version."""
if not is_macos():
info(
"Auto-update is currently only supported on macOS. "
"Please follow the update guide: https://git-mastery.github.io/app/update"
)
return

info("Detected macOS. Starting update via Homebrew...")
if run_brew_update():
success("Git-Mastery has been updated successfully!")
else:
warn("Update command finished with errors. Please check the output above.")