Skip to content

Commit

Permalink
Metavars and envvars
Browse files Browse the repository at this point in the history
  • Loading branch information
gouline committed Dec 12, 2023
1 parent 5362d0c commit fc5590e
Showing 1 changed file with 53 additions and 17 deletions.
70 changes: 53 additions & 17 deletions dbtmetabase/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ def common_options(func: Callable) -> Callable:

@click.option(
"--dbt-database",
metavar="DATABASE",
envvar="DBT_DATABASE",
show_envvar=True,
required=True,
Expand All @@ -92,45 +93,55 @@ def common_options(func: Callable) -> Callable:
"--dbt-manifest-path",
envvar="DBT_MANIFEST_PATH",
show_envvar=True,
type=click.Path(exists=True, file_okay=True, dir_okay=False),
type=click.Path(exists=True, dir_okay=False),
help="Path to dbt manifest.json file under /target/ in the dbt project directory. Uses dbt manifest parsing (recommended).",
)
@click.option(
"--dbt-project-path",
envvar="DBT_PROJECT_PATH",
show_envvar=True,
type=click.Path(exists=True, file_okay=False, dir_okay=True),
type=click.Path(exists=True, file_okay=False),
help="Path to dbt project directory containing models. Uses dbt project parsing (not recommended).",
)
@click.option(
"--dbt-schema",
metavar="SCHEMA",
envvar="DBT_SCHEMA",
show_envvar=True,
help="Target dbt schema. Must be passed if using project parser.",
type=click.STRING,
)
@click.option(
"--dbt-schema-excludes",
metavar="SCHEMAS",
envvar="DBT_SCHEMA_EXCLUDES",
show_envvar=True,
type=list,
cls=OptionEatAll,
help="Target dbt schemas to exclude. Ignored in project parser.",
)
@click.option(
"--dbt-includes",
metavar="MODELS",
envvar="DBT_INCLUDES",
show_envvar=True,
type=list,
cls=OptionEatAll,
help="Include specific dbt models names.",
)
@click.option(
"--dbt-excludes",
metavar="MODELS",
envvar="DBT_EXCLUDES",
show_envvar=True,
type=list,
cls=OptionEatAll,
help="Exclude specific dbt model names.",
)
@click.option(
"--metabase-database",
envvar="MB_DATABASE",
metavar="DATABASE",
envvar="METABASE_DATABASE",
show_envvar=True,
required=True,
type=click.STRING,
Expand All @@ -148,59 +159,68 @@ def common_options(func: Callable) -> Callable:
@click.option(
"--metabase-user",
metavar="USER",
envvar="MB_USER",
envvar="METABASE_USER",
show_envvar=True,
type=click.STRING,
help="Metabase username.",
)
@click.option(
"--metabase-password",
metavar="PASS",
envvar="MB_PASSWORD",
metavar="PASSWORD",
envvar="METABASE_PASSWORD",
show_envvar=True,
type=click.STRING,
help="Metabase password.",
)
@click.option(
"--metabase-session-id",
metavar="TOKEN",
envvar="MB_SESSION_ID",
envvar="METABASE_SESSION_ID",
show_envvar=True,
type=click.STRING,
help="Metabase session ID.",
)
@click.option(
"--metabase-http/--metabase-https",
"metabase_use_http",
envvar="METABASE_USE_HTTP",
show_envvar=True,
default=False,
help="Force HTTP instead of HTTPS to connect to Metabase.",
)
@click.option(
"--metabase-verify",
metavar="CERT",
envvar="METABASE_VERIFY",
show_envvar=True,
type=click.Path(exists=True, file_okay=True, dir_okay=False),
help="Path to certificate bundle used to connect to Metabase.",
)
@click.option(
"--metabase-sync/--metabase-sync-skip",
"metabase_sync",
envvar="METABASE_SYNC",
show_envvar=True,
default=True,
show_default=True,
help="Attempt to synchronize Metabase schema with local models.",
)
@click.option(
"--metabase-sync-timeout",
metavar="SECS",
envvar="METABASE_SYNC_TIMEOUT",
show_envvar=True,
type=click.INT,
help="Synchronization timeout in secs. When set, command fails on failed synchronization. Otherwise, command proceeds regardless. Only valid if sync is enabled.",
)
@click.option(
"--metabase-http-timeout",
type=int,
metavar="SECS",
envvar="METABASE_HTTP_TIMEOUT",
show_envvar=True,
type=click.INT,
default=15,
show_default=True,
envvar="MB_HTTP_TIMEOUT",
show_envvar=True,
help="Set the value for single requests timeout.",
)
@click.option(
Expand All @@ -221,16 +241,22 @@ def wrapper(*args, **kwargs):
@click.option(
"--dbt-docs-url",
metavar="URL",
envvar="DBT_DOCS_URL",
show_envvar=True,
type=click.STRING,
help="URL for dbt docs to be appended to table descriptions in Metabase.",
)
@click.option(
"--dbt-include-tags",
envvar="DBT_INCLUDE_TAGS",
show_envvar=True,
is_flag=True,
help="Append tags to table descriptions in Metabase.",
)
@click.option(
"--metabase-exclude-sources",
envvar="METABASE_EXCLUDE_SOURCES",
show_envvar=True,
is_flag=True,
help="Skip exporting sources to Metabase.",
)
Expand Down Expand Up @@ -308,25 +334,35 @@ def models(
@common_options
@click.option(
"--output-path",
type=click.Path(exists=True, file_okay=False, dir_okay=True, writable=True),
envvar="OUTPUT_PATH",
show_envvar=True,
type=click.Path(exists=True, file_okay=False),
default=".",
show_default=True,
help="Output path for generated exposure YAML.",
)
@click.option(
"--output-name",
metavar="NAME",
envvar="OUTPUT_NAME",
show_envvar=True,
type=click.STRING,
default="metabase_exposures.yml",
show_default=True,
help="File name for generated exposure YAML.",
)
@click.option(
"--include-personal-collections",
"--metabase-include-personal-collections",
envvar="METABASE_INCLUDE_PERSONAL_COLLECTIONS",
show_envvar=True,
is_flag=True,
help="Include personal collections when parsing exposures.",
)
@click.option(
"--collection-excludes",
"--metabase-collection-excludes",
metavar="COLLECTIONS",
envvar="METABASE_COLLECTION_EXCLUDES",
show_envvar=True,
cls=OptionEatAll,
type=list,
help="Metabase collection names to exclude.",
Expand All @@ -351,8 +387,8 @@ def exposures(
metabase_http_timeout: int,
output_path: str,
output_name: str,
include_personal_collections: bool,
collection_excludes: Optional[Iterable],
metabase_include_personal_collections: bool,
metabase_collection_excludes: Optional[Iterable],
verbose: bool,
):
if verbose:
Expand Down Expand Up @@ -394,6 +430,6 @@ def exposures(
models=dbt_models,
output_path=output_path,
output_name=output_name,
include_personal_collections=include_personal_collections,
collection_excludes=collection_excludes,
include_personal_collections=metabase_include_personal_collections,
collection_excludes=metabase_collection_excludes,
)

0 comments on commit fc5590e

Please sign in to comment.