3232 from snowflake .cli ._plugins .sql .repl import Repl
3333 from snowflake .cli .api .project .definition_manager import DefinitionManager
3434 from snowflake .cli .api .project .schemas .project_definition import ProjectDefinition
35+ from snowflake .connector .config_manager import ConfigManager
3536
3637_CONNECTION_CACHE = OpenConnectionCache ()
3738
@@ -66,13 +67,21 @@ class _CliGlobalContextManager:
6667 _definition_manager : DefinitionManager | None = None
6768 enhanced_exit_codes : bool = False
6869
70+ # Configuration management
71+ _config_manager : ConfigManager | None = None
72+ config_file_override : Path | None = None
73+ connections_file_override : Path | None = None
74+
6975 # which properties invalidate our current DefinitionManager?
7076 DEFINITION_MANAGER_DEPENDENCIES = [
7177 "project_path_arg" ,
7278 "project_is_optional" ,
7379 "project_env_overrides_args" ,
7480 ]
7581
82+ # Dependencies that invalidate config manager
83+ CONFIG_MANAGER_DEPENDENCIES = ["config_file_override" , "connections_file_override" ]
84+
7685 def reset (self ):
7786 self .__init__ ()
7887
@@ -88,6 +97,9 @@ def __setattr__(self, prop, val):
8897 if prop in self .DEFINITION_MANAGER_DEPENDENCIES :
8998 self ._clear_definition_manager ()
9099
100+ if prop in self .CONFIG_MANAGER_DEPENDENCIES :
101+ self ._clear_config_manager ()
102+
91103 super ().__setattr__ (prop , val )
92104
93105 @property
@@ -144,6 +156,75 @@ def _clear_definition_manager(self):
144156 """
145157 self ._definition_manager = None
146158
159+ @property
160+ def config_manager (self ) -> ConfigManager :
161+ """
162+ Get or create the configuration manager instance.
163+ Follows the same lazy initialization pattern as DefinitionManager.
164+ """
165+ if self ._config_manager is None :
166+ self ._config_manager = self ._create_config_manager ()
167+ return self ._config_manager
168+
169+ def _create_config_manager (self ) -> ConfigManager :
170+ """
171+ Factory method to create ConfigManager instance with CLI-specific options.
172+ Replicates the behavior of the imported CONFIG_MANAGER singleton.
173+ """
174+ import tomlkit
175+ from snowflake .cli .api .config import get_connections_file
176+ from snowflake .connector .config_manager import (
177+ ConfigManager ,
178+ ConfigSlice ,
179+ ConfigSliceOptions ,
180+ )
181+ from snowflake .connector .constants import CONFIG_FILE
182+
183+ # Get current connections file path (handles test env changes)
184+ connections_file = get_connections_file ()
185+
186+ # Create ConfigSlice for connections.toml (same as singleton CONFIG_MANAGER)
187+ connections_slice = ConfigSlice (
188+ path = connections_file ,
189+ options = ConfigSliceOptions (check_permissions = True , only_in_slice = False ),
190+ section = "connections" ,
191+ )
192+
193+ # Create manager instance with connections slice
194+ manager = ConfigManager (
195+ name = "CONFIG_MANAGER" ,
196+ file_path = self .config_file_override or CONFIG_FILE ,
197+ _slices = [connections_slice ],
198+ )
199+
200+ # Add connector's default options (replicating connector's singleton setup)
201+ manager .add_option (
202+ name = "connections" ,
203+ parse_str = tomlkit .parse ,
204+ default = dict (),
205+ )
206+
207+ manager .add_option (
208+ name = "default_connection_name" , parse_str = str , default = "default"
209+ )
210+
211+ # Add CLI-specific options (current lines 66-70 in config.py)
212+ from snowflake .cli .api .config import CLI_SECTION
213+
214+ manager .add_option (
215+ name = CLI_SECTION ,
216+ parse_str = tomlkit .parse ,
217+ default = dict (),
218+ )
219+
220+ return manager
221+
222+ def _clear_config_manager (self ):
223+ """
224+ Force re-creation of config manager when dependencies change.
225+ """
226+ self ._config_manager = None
227+
147228
148229class _CliGlobalContextAccess :
149230 def __init__ (self , manager : _CliGlobalContextManager ):
@@ -216,6 +297,21 @@ def repl(self) -> Repl | None:
216297 """Get the current REPL instance if running in REPL mode."""
217298 return self ._manager .repl_instance
218299
300+ @property
301+ def config_manager (self ) -> ConfigManager :
302+ """Get the current configuration manager."""
303+ return self ._manager .config_manager
304+
305+ @property
306+ def config_file_override (self ) -> Path | None :
307+ """Get the current config file override path."""
308+ return self ._manager .config_file_override
309+
310+ @config_file_override .setter
311+ def config_file_override (self , value : Path | None ) -> None :
312+ """Set the config file override path."""
313+ self ._manager .config_file_override = value
314+
219315
220316_CLI_CONTEXT_MANAGER : ContextVar [_CliGlobalContextManager | None ] = ContextVar (
221317 "cli_context" , default = None
0 commit comments