-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[CT-2016] [Spike] Static artifact for CLI validation #6840
Comments
FYI to Execution team: I'm going to queue this up for estimation discussion. Not expecting a point estimate (since it's a spike), just expecting that you all know more than I do about this topic & might have some strong opinions! |
Here's a Python script that will output an artifact named
import json
from click import Context
from dbt.cli.main import cli
def convert_to_serializable(obj):
# Convert non-serializable objects to strings
return str(obj)
def serialize_dict_to_json(input_dict):
# Use a custom conversion function when serializing
return json.dumps(input_dict, indent=4, default=convert_to_serializable)
with Context(cli) as ctx:
info = ctx.to_info_dict()
pretty_json_string = serialize_dict_to_json(info)
# Write the JSON string to a file
with open("dbt-core-cli-flags.json", "w") as file:
file.write(pretty_json_string) Usagepython generate_cli_flags_artifact.py Note: the dictionary can contain content that isn't serializable to JSON (like tuples, functions, etc), so this script just converts those to a string. Related internal Slack threads(Added 2024-01-12) |
Here is a script that produces the Markdown table below: |
Here's a section of the documentation that outlines which sub-commands are available in dbt Core, dbt Cloud CLI, and dbt Cloud IDE: |
The ask: A language-agnostic data structure to validate dbt CLI commands, without actually requiring
dbt-core
to be imported/installed. (Could be a JSONSchema, doesn't have to be.) Let's get away from any need for naïve regex.For starters, the goal here wouldn't even be to parse CLI strings into meaningful representations — just to say, this is or isn't a valid CLI string. But I'd also imagine wanting to extend this nicer-to-have territory (auto-complete, blocking certain options, extending with additional options).
As I see it, two options:
dbt-core
's CLI, consume that data structure to generate the CLI methods/decorators.click.cli
to a static data structure, which could then be used (itself? byclick
? by another tool?) just to validate CLI strings.The closest thing I could find built into
click
is theto_info_dict
method, which is really intended to support auto-generating documentation:https://click.palletsprojects.com/en/8.1.x/api/#click.Command.to_info_dict
The text was updated successfully, but these errors were encountered: