Open jtcohen6 opened 1 year ago
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 dbt-core-cli-flags.json
:
generate_cli_flags_artifact.py
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)
python 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.
(Added 2024-01-12)
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