Skip to content

Commit 35c4998

Browse files
committed
refactor: move token and instance-name to top-level command
1 parent 285fc83 commit 35c4998

File tree

2 files changed

+34
-14
lines changed

2 files changed

+34
-14
lines changed

src/datapilot/cli/main.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,17 @@
55

66

77
@click.group()
8-
def datapilot():
8+
@click.option("--token", required=False, help="Your API token for authentication.")
9+
@click.option("--instance-name", required=False, help="Your tenant ID.")
10+
@click.option("--backend-url", required=False, help="Altimate's Backend URL", default="https://api.myaltimate.com")
11+
@click.pass_context
12+
def datapilot(ctx, token, instance_name, backend_url):
913
"""Altimate CLI for DBT project management."""
14+
# Store common options in context
15+
ctx.ensure_object(dict)
16+
ctx.obj['token'] = token
17+
ctx.obj['instance_name'] = instance_name
18+
ctx.obj['backend_url'] = backend_url
1019

1120

1221
datapilot.add_command(dbt)

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

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,14 @@
2424

2525
# New dbt group
2626
@click.group()
27-
def dbt():
27+
@click.pass_context
28+
def dbt(ctx):
2829
"""DBT specific commands."""
30+
# Ensure context object exists
31+
ctx.ensure_object(dict)
2932

3033

3134
@dbt.command("project-health")
32-
@click.option("--token", required=False, help="Your API token for authentication.")
33-
@click.option("--instance-name", required=False, help="Your tenant ID.")
3435
@click.option(
3536
"--manifest-path",
3637
required=True,
@@ -57,21 +58,24 @@ def dbt():
5758
default=None,
5859
help="Selective model testing. Specify one or more models to run tests on.",
5960
)
60-
@click.option("--backend-url", required=False, help="Altimate's Backend URL", default="https://api.myaltimate.com")
61+
@click.pass_context
6162
def project_health(
62-
token,
63-
instance_name,
63+
ctx,
6464
manifest_path,
6565
catalog_path,
6666
config_path=None,
6767
config_name=None,
6868
select=None,
69-
backend_url="https://api.myaltimate.com",
7069
):
7170
"""
7271
Validate the DBT project's configuration and structure.
7372
:param manifest_path: Path to the DBT manifest file.
7473
"""
74+
# Get common options from parent context
75+
token = ctx.parent.obj.get('token')
76+
instance_name = ctx.parent.obj.get('instance_name')
77+
backend_url = ctx.parent.obj.get('backend_url')
78+
7579
config = None
7680
if config_path:
7781
config = load_config(config_path)
@@ -131,25 +135,32 @@ def project_health(
131135

132136

133137
@dbt.command("onboard")
134-
@click.option("--token", prompt="API Token", help="Your API token for authentication.")
135-
@click.option("--instance-name", prompt="Instance Name", help="Your tenant ID.")
136138
@click.option("--dbt_core_integration_id", prompt="DBT Core Integration ID", help="DBT Core Integration ID")
137139
@click.option(
138140
"--dbt_core_integration_environment", default="PROD", prompt="DBT Core Integration Environment", help="DBT Core Integration Environment"
139141
)
140142
@click.option("--manifest-path", required=True, prompt="Manifest Path", help="Path to the manifest file.")
141143
@click.option("--catalog-path", required=False, prompt=False, help="Path to the catalog file.")
142-
@click.option("--backend-url", required=False, help="Altimate's Backend URL", default="https://api.myaltimate.com")
144+
@click.pass_context
143145
def onboard(
144-
token,
145-
instance_name,
146+
ctx,
146147
dbt_core_integration_id,
147148
dbt_core_integration_environment,
148149
manifest_path,
149150
catalog_path,
150-
backend_url="https://api.myaltimate.com",
151151
):
152152
"""Onboard a manifest file to DBT."""
153+
# Get common options from parent context
154+
token = ctx.parent.obj.get('token')
155+
instance_name = ctx.parent.obj.get('instance_name')
156+
backend_url = ctx.parent.obj.get('backend_url')
157+
158+
# For onboard command, token and instance_name are required
159+
if not token:
160+
token = click.prompt("API Token")
161+
if not instance_name:
162+
instance_name = click.prompt("Instance Name")
163+
153164
check_token_and_instance(token, instance_name)
154165

155166
if not validate_credentials(token, backend_url, instance_name):

0 commit comments

Comments
 (0)