Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 20 additions & 26 deletions cue/cue.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,22 @@ def _augment_consolidated_output_args(ctx, args):
args.add("--inline-imports")
args.add("--out", ctx.attr.output_format)

# https://cuelang.org/docs/reference/command/cue-help-filetypes/
extension_by_filetype = {
"cue": "cue",
"json": "json",
"yaml": "yaml",
"toml": "toml",
"jsonl": "jsonl",
"jsonschema+json": "json",
"openapi+yaml", "yaml",
"proto": "proto",
"pb+proto": "proto",
"textproto": "textproto",
"go": "go",
# binary not yet supported
}

def _add_common_consolidated_output_attrs_to(attrs):
attrs.update({
"inline_imports": attr.bool(
Expand All @@ -632,12 +648,7 @@ def _add_common_consolidated_output_attrs_to(attrs):
"output_format": attr.string(
doc = "Output format",
default = "cue",
values = [
"cue",
"json",
"text",
"yaml",
],
values = extension_by_filetype.keys(),
),
"result": attr.output(
doc = """The built result in the format specified in the "output_format" attribute.""",
Expand All @@ -647,14 +658,8 @@ def _add_common_consolidated_output_attrs_to(attrs):
return attrs

def _prepare_consolidated_output_rule(name, **kwargs):
extension_by_format = {
"cue": "cue",
"json": "json",
"text": "txt",
"yaml": "yaml",
}
output_format = kwargs.get("output_format", "cue")
result = kwargs.pop("result", name + "." + extension_by_format[output_format])
result = kwargs.pop("result", name + "." + extension_by_filetype[output_format])
return kwargs | {
"result": result,
}
Expand Down Expand Up @@ -793,12 +798,7 @@ def _add_common_exported_output_attrs_to(attrs):
"output_format": attr.string(
doc = "Output format",
default = "json",
values = [
"cue",
"json",
"text",
"yaml",
],
values = extension_by_filetype.keys(),
),
"result": attr.output(
doc = """The built result in the format specified in the "output_format" attribute.""",
Expand All @@ -808,14 +808,8 @@ def _add_common_exported_output_attrs_to(attrs):
return attrs

def _prepare_exported_output_rule(name, **kwargs):
extension_by_format = {
"cue": "cue",
"json": "json",
"text": "txt",
"yaml": "yaml",
}
output_format = kwargs.get("output_format", "json")
result = kwargs.pop("result", name + "." + extension_by_format[output_format])
result = kwargs.pop("result", name + "." + extension_by_filetype[output_format])
return kwargs | {
"result": result,
}
Expand Down