Skip to content

Commit 6b4334b

Browse files
committed
refactor: remove click context usage in favor of direct parameter passing
1 parent 73bbbb3 commit 6b4334b

File tree

4 files changed

+29
-44
lines changed

4 files changed

+29
-44
lines changed

src/datapilot/cli/decorators.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -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

src/datapilot/cli/main.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,8 @@
88

99
@click.group()
1010
@click.version_option(version=__version__, prog_name="datapilot")
11-
@click.pass_context
12-
def datapilot(ctx):
11+
def datapilot():
1312
"""Altimate CLI for DBT project management."""
14-
# Ensure context object exists
15-
ctx.ensure_object(dict)
1613

1714

1815
datapilot.add_command(dbt)

src/datapilot/core/knowledge/cli.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,13 @@ def cli():
1515
@cli.command()
1616
@auth_options
1717
@click.option("--port", default=4000, help="Port to run the server on")
18-
@click.pass_context
19-
def serve(ctx, port):
18+
def serve(token, instance_name, backend_url, port):
2019
"""Serve knowledge bases via HTTP server."""
21-
# Get configuration from context
22-
token = ctx.obj.get("token")
23-
instance_name = ctx.obj.get("instance_name")
24-
backend_url = ctx.obj.get("backend_url")
25-
2620
if not token or not instance_name:
2721
click.echo(
2822
"Error: API token and instance name are required. Use --token and --instance-name options or set them in config.", err=True
2923
)
30-
ctx.exit(1)
24+
raise click.Abort()
3125

3226
# Set context data for the handler
3327
KnowledgeBaseHandler.token = token

src/datapilot/core/platforms/dbt/cli/cli.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,10 @@ def dbt():
5757
default=None,
5858
help="Selective model testing. Specify one or more models to run tests on.",
5959
)
60-
@click.pass_context
6160
def project_health(
62-
ctx,
61+
token,
62+
instance_name,
63+
backend_url,
6364
manifest_path,
6465
catalog_path,
6566
config_path=None,
@@ -70,10 +71,6 @@ def project_health(
7071
Validate the DBT project's configuration and structure.
7172
:param manifest_path: Path to the DBT manifest file.
7273
"""
73-
# Get common options from context
74-
token = ctx.obj.get("token")
75-
instance_name = ctx.obj.get("instance_name")
76-
backend_url = ctx.obj.get("backend_url")
7774

7875
config = None
7976
if config_path:
@@ -141,19 +138,16 @@ def project_health(
141138
)
142139
@click.option("--manifest-path", required=True, prompt="Manifest Path", help="Path to the manifest file.")
143140
@click.option("--catalog-path", required=False, prompt=False, help="Path to the catalog file.")
144-
@click.pass_context
145141
def onboard(
146-
ctx,
142+
token,
143+
instance_name,
144+
backend_url,
147145
dbt_core_integration_id,
148146
dbt_core_integration_environment,
149147
manifest_path,
150148
catalog_path,
151149
):
152150
"""Onboard a manifest file to DBT."""
153-
# Get common options from context
154-
token = ctx.obj.get("token")
155-
instance_name = ctx.obj.get("instance_name")
156-
backend_url = ctx.obj.get("backend_url")
157151

158152
# For onboard command, token and instance_name are required
159153
if not token:

0 commit comments

Comments
 (0)