@@ -16,33 +16,26 @@ class EnvFormatter:
1616 """
1717
1818 @staticmethod
19- def format_to_file (env_vars : dict [str , list [str ]], output_path : str | None = None ) -> str :
19+ def format_to_string (env_vars : dict [str , list [str ]]) -> str :
2020 """
21- Format environment variables and write to .env.example.mci file .
21+ Format environment variables as a string in .env format .
2222
2323 Args:
2424 env_vars: Dictionary mapping variable names to list of locations where used
25- output_path: Optional custom output path (default: .env.example.mci)
2625
2726 Returns:
28- Path to the generated file
27+ Formatted string in .env format
2928
3029 Example:
31- >>> env_vars = {
32- ... "API_KEY": ["main", "weather-toolset"],
33- ... "DB_URL": ["database-toolset"]
34- ... }
35- >>> path = EnvFormatter.format_to_file(env_vars)
36- >>> print(path)
37- .env.example.mci
30+ >>> env_vars = {"API_KEY": ["main"], "DB_URL": ["database-toolset"]}
31+ >>> print(EnvFormatter.format_to_string(env_vars))
32+ # .env.example.mci
33+ ...
3834 """
39- if output_path is None :
40- output_path = ".env.example.mci"
41-
4235 # Sort variables alphabetically
4336 sorted_vars = sorted (env_vars .keys ())
4437
45- # Generate file content
38+ # Generate content
4639 lines : list [str ] = []
4740 lines .append ("# .env.example.mci" )
4841 lines .append ("# Environment variables used in MCI configuration" )
@@ -58,46 +51,33 @@ def format_to_file(env_vars: dict[str, list[str]], output_path: str | None = Non
5851 lines .append (f"{ var_name } =" )
5952 lines .append ("" )
6053
61- # Write to file
62- content = "\n " .join (lines )
63- Path (output_path ).write_text (content )
64-
65- return output_path
54+ return "\n " .join (lines )
6655
6756 @staticmethod
68- def format_to_string (env_vars : dict [str , list [str ]]) -> str :
57+ def format_to_file (env_vars : dict [str , list [str ]], output_path : str | None = None ) -> str :
6958 """
70- Format environment variables as a string in .env format .
59+ Format environment variables and write to .env.example.mci file .
7160
7261 Args:
7362 env_vars: Dictionary mapping variable names to list of locations where used
63+ output_path: Optional custom output path (default: .env.example.mci)
7464
7565 Returns:
76- Formatted string in .env format
66+ Path to the generated file
7767
7868 Example:
79- >>> env_vars = {"API_KEY": ["main"], "DB_URL": ["database-toolset"]}
80- >>> print(EnvFormatter.format_to_string(env_vars))
81- # .env.example.mci
82- ...
69+ >>> env_vars = {
70+ ... "API_KEY": ["main", "weather-toolset"],
71+ ... "DB_URL": ["database-toolset"]
72+ ... }
73+ >>> path = EnvFormatter.format_to_file(env_vars)
74+ >>> print(path)
75+ .env.example.mci
8376 """
84- # Sort variables alphabetically
85- sorted_vars = sorted (env_vars .keys ())
86-
87- # Generate content
88- lines : list [str ] = []
89- lines .append ("# .env.example.mci" )
90- lines .append ("# Environment variables used in MCI configuration" )
91- lines .append ("#" )
92- lines .append ("# Copy this file to .env.mci and fill in your values" )
93- lines .append ("" )
77+ if output_path is None :
78+ output_path = ".env.example.mci"
9479
95- for var_name in sorted_vars :
96- locations = env_vars [var_name ]
97- # Add comment showing where the variable is used
98- location_str = ", " .join (sorted (locations ))
99- lines .append (f"# Used in: { location_str } " )
100- lines .append (f"{ var_name } =" )
101- lines .append ("" )
80+ content = EnvFormatter .format_to_string (env_vars )
81+ Path (output_path ).write_text (content )
10282
103- return " \n " . join ( lines )
83+ return output_path
0 commit comments