Coverage for src\gibr\cli\alias.py: 100%
18 statements
« prev ^ index » next coverage.py v7.11.0, created at 2025-10-20 09:51 +0300
« prev ^ index » next coverage.py v7.11.0, created at 2025-10-20 09:51 +0300
1"""CLI command to add git aliases for gibr commands."""
3import os
5import click
6from git import GitConfigParser
8from gibr.notify import party, success
11@click.command("alias")
12@click.pass_context
13def alias(ctx):
14 """Add git aliases for gibr commands."""
15 commands = [
16 name for name, cmd in ctx.parent.command.commands.items() if name != "alias"
17 ]
19 try:
20 config = GitConfigParser(os.path.expanduser("~/.gitconfig"), read_only=False)
21 for name in commands:
22 cmd = f"!gibr git {name}"
23 config.set_value("alias", name, cmd)
24 success(f"Added git alias: git {name} → {cmd}")
25 config.write()
26 party("Git aliases successfully added!")
27 except Exception as e:
28 raise click.ClickException(f"Failed to set git aliases: {e}")