Coverage for /Users/antonigmitruk/golf/src/golf/commands/build.py: 0%

17 statements  

« prev     ^ index     » next       coverage.py v7.6.12, created at 2025-08-16 18:46 +0200

1"""Build command for GolfMCP. 

2 

3This module implements the `golf build` command which generates a standalone 

4FastMCP application from a GolfMCP project. 

5""" 

6 

7import argparse 

8from pathlib import Path 

9 

10from rich.console import Console 

11 

12from golf.core.builder import build_project as core_build_project 

13from golf.core.config import Settings, load_settings 

14 

15console = Console() 

16 

17 

18def build_project( 

19 project_path: Path, 

20 settings: Settings, 

21 output_dir: Path, 

22 build_env: str = "prod", 

23 copy_env: bool = False, 

24) -> None: 

25 """Build a standalone FastMCP application from a GolfMCP project. 

26 

27 Args: 

28 project_path: Path to the project root 

29 settings: Project settings 

30 output_dir: Directory to output the built project 

31 build_env: Build environment ('dev' or 'prod') 

32 copy_env: Whether to copy environment variables to the built app 

33 """ 

34 # Call the centralized build function from core.builder 

35 core_build_project(project_path, settings, output_dir, build_env=build_env, copy_env=copy_env) 

36 

37 

38# Add a main section to run the build_project function when this module is 

39# executed directly 

40if __name__ == "__main__": 

41 parser = argparse.ArgumentParser(description="Build a standalone FastMCP application") 

42 parser.add_argument( 

43 "--project-path", 

44 "-p", 

45 type=Path, 

46 default=Path.cwd(), 

47 help="Path to the project root (default: current directory)", 

48 ) 

49 parser.add_argument( 

50 "--output-dir", 

51 "-o", 

52 type=Path, 

53 default=Path.cwd() / "dist", 

54 help="Directory to output the built project (default: ./dist)", 

55 ) 

56 parser.add_argument( 

57 "--build-env", 

58 type=str, 

59 default="prod", 

60 choices=["dev", "prod"], 

61 help="Build environment to use (default: prod)", 

62 ) 

63 parser.add_argument( 

64 "--copy-env", 

65 action="store_true", 

66 help="Copy environment variables to the built application", 

67 ) 

68 

69 args = parser.parse_args() 

70 

71 # Load settings from the project path 

72 settings = load_settings(args.project_path) 

73 

74 # Execute the build 

75 build_project( 

76 args.project_path, 

77 settings, 

78 args.output_dir, 

79 build_env=args.build_env, 

80 copy_env=args.copy_env, 

81 )