Skip to content

Conversation

@efung
Copy link

@efung efung commented Jan 31, 2024

What

Integrate the output of the Click shell completion script into this one. This gives this script completion for commands and parameters, while preserving the previous functionality.

Resolves #20

How

I ran _DBT_COMPLETE=bash_source dbt and then added it to an else block in the check that looks for the selector flag. In addition, since this introduces a dependency on dbt on this script, I added a check for dbt to bail out early if it's not actually installed or available.

Sample shell transcript

$ dbt <tab>
build          debug          init           run            show           test
clean          deps           list           run-operation  snapshot
compile        docs           parse          seed           source

$ dbt --no-<tab>
--no-cache-selected-only         --no-populate-cache              --no-use-colors
--no-debug                       --no-print                       --no-use-colors-file
--no-fail-fast                   --no-quiet                       --no-use-experimental-parser
--no-log-cache-events            --no-send-anonymous-usage-stats  --no-version-check
--no-partial-parse               --no-static-parser               --no-write-json

$ dbt run --no<tab>
--no-defer          --no-fail-fast      --no-favor-state    --no-version-check

$ dbt run --no-defer -s m<tab>
my_first_dbt_model

Testing

I'm using dbt 1.5.2 on macOS 14.3. The dbt version shouldn't matter, as the completion uses the current dbt.

@b-per b-per self-requested a review March 7, 2024 22:57
@b-per
Copy link
Contributor

b-per commented Mar 7, 2024

Hi @efung ! Thanks for this.

I am off for a bit but will have a look in the next couple of weeks

@b-per
Copy link
Contributor

b-per commented Mar 25, 2024

I have done a couple of tests but will need to do more and most likely modify slightly this PR. It might take a few days.

The first issue I see is that dbt can now also mean the dbt Cloud CLI, which is not built on Click, so, in that case, the completion fails. We'll need to have a mechanism to know if the current dbt is dbt-core or the dbt Cloud CLI

I also want to test the performance a bit. The first tests I did on my machine were quite slow (~1 sec to return completion results), whereas the (incomplete) current version returns results immediately.

@b-per
Copy link
Contributor

b-per commented Mar 25, 2024

I just raised an issue in dbt-core about the performance hit of this approach and whether it can be fixed on the Core side

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support completion of subcommands and their arguments

2 participants