From 0042b7513a12cab4518cd2a7cb258b56c612c097 Mon Sep 17 00:00:00 2001 From: Jake Beresford Date: Tue, 18 Jul 2023 16:56:34 -0400 Subject: [PATCH] Add support for yaml selectors to relevant commands Not having this has started to be a thorn in my side --- palm/plugins/dbt/commands/cmd_compile.py | 5 +++++ palm/plugins/dbt/commands/cmd_run.py | 7 +++++++ palm/plugins/dbt/commands/cmd_seed.py | 5 +++++ palm/plugins/dbt/commands/cmd_test.py | 7 +++++++ 4 files changed, 24 insertions(+) diff --git a/palm/plugins/dbt/commands/cmd_compile.py b/palm/plugins/dbt/commands/cmd_compile.py index 54d9a69..0aebbb9 100644 --- a/palm/plugins/dbt/commands/cmd_compile.py +++ b/palm/plugins/dbt/commands/cmd_compile.py @@ -6,12 +6,14 @@ @click.command("compile") @click.option("--models", "-m", multiple=True, help="See dbt docs on models flag") @click.option("--select", "-s", multiple=True, help="See dbt docs on select flag") +@click.option("--selector", multiple=True, help="See dbt docs on selector flag") @click.option("--exclude", "-e", multiple=True, help="See dbt docs on exclude flag") @click.pass_obj def cli( environment, models: Optional[Tuple] = tuple(), select: Optional[Tuple] = tuple(), + selector: Optional[Tuple] = tuple(), exclude: Optional[Tuple] = tuple(), ): """Compiles the dbt repo""" @@ -24,6 +26,9 @@ def cli( if targets: cmd.append("--select") cmd.extend(targets) + if selector: + cmd.append("--selector") + cmd.extend(selector) if exclude: cmd.append('--exclude') cmd.extend(exclude) diff --git a/palm/plugins/dbt/commands/cmd_run.py b/palm/plugins/dbt/commands/cmd_run.py index ffef0ac..5818a8d 100644 --- a/palm/plugins/dbt/commands/cmd_run.py +++ b/palm/plugins/dbt/commands/cmd_run.py @@ -14,6 +14,7 @@ @click.option("--clean", is_flag=True, help="Drop the test schema after the run") @click.option("--models", "-m", multiple=True, help="See dbt docs on models flag") @click.option("--select", "-s", multiple=True, help="See dbt docs on select flag") +@click.option("--selector", multiple=True, help="See dbt docs on selector flag") @click.option("--exclude", "-e", multiple=True, help="See dbt docs on exclude flag") @click.option("--defer", "-d", is_flag=True, help="See dbt docs on defer flag") @click.option("--iterative", "-i", is_flag=True, help="Iterative stateful dbt run") @@ -35,6 +36,7 @@ def cli( seed: bool, models: Optional[Tuple] = tuple(), select: Optional[Tuple] = tuple(), + selector: Optional[Tuple] = tuple(), exclude: Optional[Tuple] = tuple(), vars: Optional[str] = None, ): @@ -67,6 +69,7 @@ def cli( seed=seed, no_fail_fast=(no_fail_fast or iterative), targets=targets, + selector=selector, exclude=exclude, defer=defer, vars=vars, @@ -104,6 +107,7 @@ def build_run_command( seed: bool = True, no_fail_fast: bool = False, targets: Optional[list] = None, + selector: Optional[Tuple] = None, exclude: Optional[Tuple] = None, defer: bool = False, vars: Optional[str] = None, @@ -119,6 +123,9 @@ def build_run_command( if targets: cmd.append("--select") cmd.extend(targets) + if selector: + cmd.append("--selector") + cmd.extend(selector) if exclude: cmd.append("--exclude") cmd.extend(exclude) diff --git a/palm/plugins/dbt/commands/cmd_seed.py b/palm/plugins/dbt/commands/cmd_seed.py index a9bddd5..7b21570 100644 --- a/palm/plugins/dbt/commands/cmd_seed.py +++ b/palm/plugins/dbt/commands/cmd_seed.py @@ -8,6 +8,7 @@ "--clean", is_flag=True, help="drop the test schema after the run is complete" ) @click.option("--select", '-s', multiple=True, help="see dbt docs on select flag") +@click.option("--selector", multiple=True, help="see dbt docs on selector flag") @click.option("--exclude", '-e', multiple=True, help="see dbt docs on exclude flag") @click.option( "--no-full-refresh", @@ -21,6 +22,7 @@ def cli( clean: bool, no_full_refresh: bool, select: Optional[Tuple] = tuple(), + selector: Optional[Tuple] = tuple(), exclude: Optional[Tuple] = tuple(), ): """Run dbt seeds""" @@ -29,6 +31,9 @@ def cli( if select: cmd.append('--select') cmd.extend(select) + if selector: + cmd.append('--selector') + cmd.extend(selector) if exclude: cmd.append('--exclude') cmd.extend(exclude) diff --git a/palm/plugins/dbt/commands/cmd_test.py b/palm/plugins/dbt/commands/cmd_test.py index 0f2bd69..ce03789 100644 --- a/palm/plugins/dbt/commands/cmd_test.py +++ b/palm/plugins/dbt/commands/cmd_test.py @@ -10,6 +10,7 @@ ) @click.option("--models", "-m", multiple=True, help="See dbt docs on models flag") @click.option("--select", "-s", multiple=True, help="See dbt docs on select flag") +@click.option("--selector", multiple=True, help="See dbt docs on selector flag") @click.option("--exclude", "-e", multiple=True, help="See dbt docs on exclude flag") @click.option("--defer", "-d", is_flag=True, help="See dbt docs on defer flag") @click.option( @@ -23,6 +24,7 @@ def cli( defer: bool, models: Optional[Tuple] = tuple(), select: Optional[Tuple] = tuple(), + selector: Optional[Tuple] = tuple(), exclude: Optional[Tuple] = tuple(), ): """Tests the dbt repo""" @@ -50,6 +52,7 @@ def cli( run_cmd = build_test_command( no_fail_fast=no_fail_fast, targets=targets, + selector=selector, exclude=exclude, defer=defer, ) @@ -67,6 +70,7 @@ def build_test_command( defer: bool = False, no_fail_fast: bool = False, targets: Optional[list] = None, + selector: Optional[Tuple] = None, exclude: Optional[Tuple] = None, ) -> str: cmd = [] @@ -75,6 +79,9 @@ def build_test_command( if targets: cmd.append('--select') cmd.extend(targets) + if selector: + cmd.append('--selector') + cmd.extend(selector) if exclude: cmd.append('--exclude') cmd.extend(exclude)