@@ -54,7 +54,7 @@ def auth_options(f):
5454 @click .option ("--instance-name" , required = False , help = "Your tenant ID." )
5555 @click .option ("--backend-url" , required = False , help = "Altimate's Backend URL" , default = "https://api.myaltimate.com" )
5656 @wraps (f )
57- def wrapper (ctx , token , instance_name , backend_url , * args , ** kwargs ):
57+ def wrapper (token , instance_name , backend_url , * args , ** kwargs ):
5858 # Load .env file from current directory if it exists
5959 load_dotenv ()
6060
@@ -65,27 +65,27 @@ def wrapper(ctx, token, instance_name, backend_url, *args, **kwargs):
6565 # Map config file keys to CLI option names
6666 config_mapping = {"altimateApiKey" : "token" , "altimateInstanceName" : "instance_name" , "altimateUrl" : "backend_url" }
6767
68- # Store common options in context
69- ctx .ensure_object (dict )
68+ # Apply file config first, then override with CLI arguments if provided
69+ final_token = token
70+ final_instance_name = instance_name
71+ final_backend_url = backend_url
7072
71- # Apply file config first
72- for file_key , cli_key in config_mapping .items ():
73- if file_key in file_config :
74- ctx .obj [cli_key ] = file_config [file_key ]
75-
76- # Override with CLI arguments if provided
77- if token is not None :
78- ctx .obj ["token" ] = token
79- if instance_name is not None :
80- ctx .obj ["instance_name" ] = instance_name
81- if backend_url != "https://api.myaltimate.com" : # Only override if not default
82- ctx .obj ["backend_url" ] = backend_url
73+ # Use file config if CLI argument not provided
74+ if final_token is None and "altimateApiKey" in file_config :
75+ final_token = file_config ["altimateApiKey" ]
76+ if final_instance_name is None and "altimateInstanceName" in file_config :
77+ final_instance_name = file_config ["altimateInstanceName" ]
78+ if final_backend_url == "https://api.myaltimate.com" and "altimateUrl" in file_config :
79+ final_backend_url = file_config ["altimateUrl" ]
8380
8481 # Set defaults if nothing was provided
85- ctx .obj .setdefault ("token" , None )
86- ctx .obj .setdefault ("instance_name" , None )
87- ctx .obj .setdefault ("backend_url" , "https://api.myaltimate.com" )
88-
89- return f (ctx , * args , ** kwargs )
82+ if final_token is None :
83+ final_token = None
84+ if final_instance_name is None :
85+ final_instance_name = None
86+ if final_backend_url is None :
87+ final_backend_url = "https://api.myaltimate.com"
88+
89+ return f (final_token , final_instance_name , final_backend_url , * args , ** kwargs )
9090
9191 return wrapper
0 commit comments