Accelerate your documentation workflow: Generate docs for whole folders at once

This is a companion discussion topic for the original entry at Accelerate your documentation workflow: Generate docs for whole folders at once | dbt Developer Blog

Just to add on this, I use

MY_MODELS=$(dbt -q ls -m my/path/to/models  --output name | xargs -I{} echo -n ' "{}",' | sed 's/,*$//' | sed 's/\(.*\)/[\1]/')
# returns ["model_a", "model_b"]

where dbt -q trims out any logs and leaves just the output, and the two consecutive sed remove the last trailing comma and wraps the result in square brackets, respectively.

then,

dbt -q run-operation generate_model_yaml --args '{"model_names": '"$MY_MODELS"' }'

notice that using single quotes renders the variable as a literal value, to expand it we need to close the quotes before the variable and reopen them again after using it, like 'my'"$VAR"'is cool'. see shell - Expansion of variables inside single quotes in a command in Bash - Stack Overflow for details.