1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
"""Command-line entry point for pygittools (pgt)."""
from __future__ import annotations
import argparse
import sys
from pathlib import Path
import pygittools
from pygittools.tags_sync import format_sync_result, sync_board_tags
from pygittools.tasks_query import open_repository, resolve_repo_location
from pygittools.tui import run_tui
def build_parser() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser(
prog="pgt",
description=pygittools.__description__,
)
parser.add_argument(
"--repo",
type=Path,
help="Path to a git repository (default: discover from the current directory)",
)
parser.add_argument(
"--version",
action="version",
version=f"%(prog)s {pygittools.__version__}",
)
subparsers = parser.add_subparsers(dest="command")
tags_parser = subparsers.add_parser("tags", help="Task tag operations")
tags_subparsers = tags_parser.add_subparsers(dest="tags_command", required=True)
sync_parser = tags_subparsers.add_parser("sync", help="Pull and push board task tags with a remote")
sync_parser.add_argument(
"--remote",
default="origin",
help="Remote name to sync with (for example origin)",
)
sync_parser.add_argument(
"--board",
default="Tasks",
help="Board name under refs/tags/boards/ (default: Tasks)",
)
return parser
def _run_tags_sync(repo_path: Path | None, remote: str, board: str) -> int:
location = resolve_repo_location(repo_path=repo_path)
repo = open_repository(location)
try:
result = sync_board_tags(repo, remote, board)
except (KeyError, RuntimeError, ValueError) as exc:
print(exc, file=sys.stderr)
return 1
print(format_sync_result(result))
return 0
def main(argv: list[str] | None = None) -> int:
args_list = sys.argv[1:] if argv is None else argv
if not args_list:
return run_tui()
parser = build_parser()
args = parser.parse_args(args_list)
if args.command == "tags" and args.tags_command == "sync":
return _run_tags_sync(args.repo, args.remote, args.board)
return run_tui(args.repo)
if __name__ == "__main__":
raise SystemExit(main())