Skip to content

Commit

Permalink
feat: add hooks command group as a subcommand of claudesync
Browse files Browse the repository at this point in the history
  • Loading branch information
guidodinello committed Dec 21, 2024
1 parent ad72284 commit 0295a74
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 19 deletions.
53 changes: 34 additions & 19 deletions src/claudesync/cli/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,39 @@
]


@click.group()
def hooks():
"""Manage Git hooks for the project."""
pass


@hooks.command()
def install():
"""Install Git hooks for automatic code formatting."""
project_root = find_git_root()
if not project_root:
click.echo("Error: Not a git repository (or any of the parent directories)")
return

hooks_dir = project_root / ".git" / "hooks"
if not hooks_dir.exists():
click.echo(f"Creating hooks directory: {hooks_dir}")
hooks_dir.mkdir(parents=True, exist_ok=True)

for hook in SUPPORTED_GIT_HOOKS:
copy_hook(hooks_dir, hook)

click.echo("\nHook installation complete!")


@hooks.command()
def list():
"""List available Git hooks."""
click.echo("Available hooks:")
for hook in SUPPORTED_GIT_HOOKS:
click.echo(f" - {hook}")


def copy_hook(hooks_dir, hook_name):
"""
Copy a specific hook from templates to git hooks directory.
Expand Down Expand Up @@ -39,24 +72,6 @@ def copy_hook(hooks_dir, hook_name):
click.echo(f"Error installing {hook_name} hook: {e}")


def install_hooks():
"""Install all supported Git hooks for the project."""
project_root = find_git_root()
if not project_root:
click.echo("Error: Not a git repository (or any of the parent directories)")
return

hooks_dir = project_root / ".git" / "hooks"
if not hooks_dir.exists():
click.echo(f"Creating hooks directory: {hooks_dir}")
hooks_dir.mkdir(parents=True, exist_ok=True)

for hook in SUPPORTED_GIT_HOOKS:
copy_hook(hooks_dir, hook)

click.echo("\nHook installation complete!")


def find_git_root():
"""Find the root directory of the Git repository"""
try:
Expand All @@ -72,4 +87,4 @@ def find_git_root():


if __name__ == "__main__":
install_hooks()
install()
2 changes: 2 additions & 0 deletions src/claudesync/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from .project import project
from .sync import schedule
from .config import config
from .hooks import hooks
import logging

logging.basicConfig(
Expand Down Expand Up @@ -213,6 +214,7 @@ def sync_submodule(provider, config, submodule, category):
cli.add_command(schedule)
cli.add_command(config)
cli.add_command(chat)
cli.add_command(hooks)

if __name__ == "__main__":
cli()

0 comments on commit 0295a74

Please sign in to comment.