Coverage for src/github_actions_practice/main.py: 77%

35 statements  

« prev     ^ index     » next       coverage.py v7.10.1, created at 2025-08-04 09:35 +0000

1#!/usr/bin/env python3 

2"""主程式模組 - 示範基本功能供 GitHub Actions 測試使用.""" 

3 

4import click 

5from .utils import fetch_data, process_data 

6from .web import create_project_report 

7 

8 

9@click.command() 

10@click.option("--name", default="World", help="要問候的名字") 

11@click.option("--count", default=1, help="重複次數") 

12def hello(name: str, count: int) -> None: 

13 """簡單的問候程式.""" 

14 for _ in range(count): 

15 click.echo(f"Hello {name}!") 

16 

17 

18@click.command() 

19@click.option("--url", default="https://httpbin.org/json", help="要取得資料的 URL") 

20def fetch(url: str) -> None: 

21 """從 URL 取得資料並處理.""" 

22 try: 

23 data = fetch_data(url) 

24 result = process_data(data) 

25 click.echo(f"處理結果: {result}") 

26 except Exception as e: 

27 click.echo(f"錯誤: {e}", err=True) 

28 raise 

29 

30 

31@click.command() 

32def report() -> None: 

33 """生成專案報告網頁.""" 

34 try: 

35 create_project_report() 

36 click.echo("✅ 專案報告已生成在 docs/index.html") 

37 except Exception as e: 

38 click.echo(f"錯誤: {e}", err=True) 

39 raise 

40 

41 

42@click.group() 

43def cli() -> None: 

44 """GitHub Actions 練習程式.""" 

45 pass 

46 

47 

48cli.add_command(hello) 

49cli.add_command(fetch) 

50cli.add_command(report) 

51 

52 

53if __name__ == "__main__": 

54 cli()