Coverage for src / mysingle / cli / protos / commands / info.py: 0%

42 statements  

« prev     ^ index     » next       coverage.py v7.12.0, created at 2025-12-02 00:58 +0900

1""" 

2Info 명령 - Proto 패키지 버전 및 상태 정보 확인. 

3""" 

4 

5from __future__ import annotations 

6 

7import argparse 

8import re 

9 

10from ..models import ProtoConfig 

11from ..utils import Color, LogLevel, colorize, log, log_header 

12 

13 

14def get_current_proto_version(config: ProtoConfig) -> str | None: 

15 """pyproject.toml에서 현재 proto 버전 추출""" 

16 path = config.repo_root / "pyproject.toml" 

17 if not path.exists(): 

18 return None 

19 

20 content = path.read_text(encoding="utf-8") 

21 match = re.search(r'^version\s*=\s*"([^"\n]+)"', content, flags=re.MULTILINE) 

22 return match.group(1) if match else None 

23 

24 

25def check_git_status(config: ProtoConfig) -> dict[str, str | bool]: 

26 """Git 상태 확인""" 

27 import subprocess 

28 

29 status: dict[str, str | bool] = {"is_clean": False, "current_branch": ""} 

30 

31 try: 

32 # 작업 트리 상태 확인 

33 result = subprocess.run( 

34 ["git", "status", "--porcelain"], 

35 cwd=config.repo_root, 

36 capture_output=True, 

37 text=True, 

38 check=True, 

39 ) 

40 status["is_clean"] = not result.stdout.strip() 

41 

42 # 현재 브랜치 확인 

43 result = subprocess.run( 

44 ["git", "rev-parse", "--abbrev-ref", "HEAD"], 

45 cwd=config.repo_root, 

46 capture_output=True, 

47 text=True, 

48 check=True, 

49 ) 

50 status["current_branch"] = result.stdout.strip() 

51 

52 except (subprocess.CalledProcessError, FileNotFoundError): 

53 pass 

54 

55 return status 

56 

57 

58def setup_parser(parser: argparse.ArgumentParser) -> None: 

59 """파서 설정""" 

60 parser.add_argument( 

61 "--check-git", 

62 action="store_true", 

63 help="Git 상태도 함께 확인", 

64 ) 

65 

66 

67def execute(args: argparse.Namespace, config: ProtoConfig) -> int: 

68 """Info 명령 실행""" 

69 log_header("Proto 패키지 정보") 

70 

71 # 패키지 버전 

72 version = get_current_proto_version(config) 

73 if version: 

74 log( 

75 f"현재 버전: {colorize(f'v{version}', Color.BRIGHT_GREEN, bold=True)}", 

76 LogLevel.INFO, 

77 ) 

78 else: 

79 log("버전 정보를 찾을 수 없습니다.", LogLevel.WARNING) 

80 return 1 

81 

82 # Git 상태 (옵션) 

83 if args.check_git: 

84 git_status = check_git_status(config) 

85 

86 branch = git_status.get("current_branch") 

87 if branch and isinstance(branch, str): 

88 log( 

89 f"현재 브랜치: {colorize(branch, Color.CYAN)}", 

90 LogLevel.INFO, 

91 ) 

92 

93 if git_status.get("is_clean"): 

94 log("Git 작업 트리: ✅ 깨끗함", LogLevel.SUCCESS) 

95 else: 

96 log("Git 작업 트리: ⚠️ 변경사항 있음", LogLevel.WARNING) 

97 

98 # GitHub 릴리즈 URL 

99 log( 

100 f"\n📦 GitHub 릴리즈: {colorize(f'https://github.com/Br0therDan/mysingle-pack/releases/tag/v{version}', Color.BRIGHT_BLUE)}", 

101 LogLevel.INFO, 

102 ) 

103 

104 return 0