1313def load_config_from_file ():
1414 """Load configuration from ~/.altimate/altimate.json if it exists."""
1515 config_path = Path .home () / ".altimate" / "altimate.json"
16-
16+
1717 if not config_path .exists ():
1818 return {}
19-
19+
2020 try :
21- with open (config_path , 'r' ) as f :
21+ with open (config_path ) as f :
2222 config = json .load (f )
2323 return config
24- except (json .JSONDecodeError , IOError ) as e :
24+ except (OSError , json .JSONDecodeError ) as e :
2525 click .echo (f"Warning: Failed to load config from { config_path } : { e } " , err = True )
2626 return {}
2727
@@ -30,14 +30,14 @@ def substitute_env_vars(value):
3030 """Replace ${env:ENV_VARIABLE} patterns with actual environment variable values."""
3131 if not isinstance (value , str ):
3232 return value
33-
33+
3434 # Pattern to match ${env:VARIABLE_NAME}
35- pattern = r' \$\{env:([^}]+)\}'
36-
35+ pattern = r" \$\{env:([^}]+)\}"
36+
3737 def replacer (match ):
3838 env_var = match .group (1 )
3939 return os .environ .get (env_var , match .group (0 ))
40-
40+
4141 return re .sub (pattern , replacer , value )
4242
4343
@@ -58,38 +58,34 @@ def datapilot(ctx, token, instance_name, backend_url):
5858 """Altimate CLI for DBT project management."""
5959 # Load .env file from current directory if it exists
6060 load_dotenv ()
61-
61+
6262 # Load configuration from file
6363 file_config = load_config_from_file ()
6464 file_config = process_config (file_config )
65-
65+
6666 # Map config file keys to CLI option names
67- config_mapping = {
68- 'altimateApiKey' : 'token' ,
69- 'altimateInstanceName' : 'instance_name' ,
70- 'altimateUrl' : 'backend_url'
71- }
72-
67+ config_mapping = {"altimateApiKey" : "token" , "altimateInstanceName" : "instance_name" , "altimateUrl" : "backend_url" }
68+
7369 # Store common options in context, with CLI args taking precedence
7470 ctx .ensure_object (dict )
75-
71+
7672 # Apply file config first
7773 for file_key , cli_key in config_mapping .items ():
7874 if file_key in file_config :
7975 ctx .obj [cli_key ] = file_config [file_key ]
80-
76+
8177 # Override with CLI arguments if provided
8278 if token is not None :
83- ctx .obj [' token' ] = token
79+ ctx .obj [" token" ] = token
8480 if instance_name is not None :
85- ctx .obj [' instance_name' ] = instance_name
81+ ctx .obj [" instance_name" ] = instance_name
8682 if backend_url != "https://api.myaltimate.com" : # Only override if not default
87- ctx .obj [' backend_url' ] = backend_url
88-
83+ ctx .obj [" backend_url" ] = backend_url
84+
8985 # Set defaults if nothing was provided
90- ctx .obj .setdefault (' token' , None )
91- ctx .obj .setdefault (' instance_name' , None )
92- ctx .obj .setdefault (' backend_url' , ' https://api.myaltimate.com' )
86+ ctx .obj .setdefault (" token" , None )
87+ ctx .obj .setdefault (" instance_name" , None )
88+ ctx .obj .setdefault (" backend_url" , " https://api.myaltimate.com" )
9389
9490
9591datapilot .add_command (dbt )
0 commit comments