From 8b3cc67f7a88d2a68291824fde95506dd3162911 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Tue, 13 Aug 2024 17:55:56 +0100 Subject: [PATCH] cmd/cue: prefer ndjson over ldjson MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Per https://github.com/ndjson/ndjson-spec/issues/3 in 2014, the ldjson spec (line-delimited JSON) was renamed to ndjson (newline-delimited JSON) and so we should use the newer extension. We already supported loading files with the ndjson extension, but `cue import` still only supported ldjson. Use ndjson in all the documentation and examples, but continue to support ldjson for backwards compatibility. Any non-encoding tests which used ldjson files now use ndjson files for the sake of consistency. Signed-off-by: Daniel Martí Change-Id: Iff4a853ed5cfc34aaecece523782c4154e3e6e63 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1199412 Reviewed-by: Matthew Sackman Unity-Result: CUE porcuepine TryBot-Result: CUEcueckoo --- cmd/cue/cmd/help.go | 2 +- cmd/cue/cmd/import.go | 6 +++--- cmd/cue/cmd/testdata/script/embed_err.txtar | 8 ++++---- cmd/cue/cmd/testdata/script/encoding_jsonl.txtar | 2 +- cue/interpreter/embed/embed.go | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/cmd/cue/cmd/help.go b/cmd/cue/cmd/help.go index 355d294869b..b1f911f0ff4 100644 --- a/cmd/cue/cmd/help.go +++ b/cmd/cue/cmd/help.go @@ -518,7 +518,7 @@ var filetypeHelp = &cobra.Command{ json .json JSON files. yaml .yaml/.yml YAML files. toml .toml TOML files - jsonl .jsonl/.ldjson Line-separated JSON values. + jsonl .jsonl/.ndjson Line-separated JSON values. jsonschema JSON Schema. openapi OpenAPI schema. pb Use Protobuf mappings (e.g. json+pb) diff --git a/cmd/cue/cmd/import.go b/cmd/cue/cmd/import.go index 8c62e5c982b..a366a9a547b 100644 --- a/cmd/cue/cmd/import.go +++ b/cmd/cue/cmd/import.go @@ -53,7 +53,7 @@ more info). This behavior can be overridden by specifying one of the following modes: Mode Extensions - json Look for JSON files (.json, .jsonl, .ldjson). + json Look for JSON files (.json .jsonl .ndjson). yaml Look for YAML files (.yaml .yml). toml Look for TOML files (.toml). text Look for text files (.txt). @@ -269,7 +269,7 @@ Example: func runImport(cmd *Command, args []string) (err error) { c := &config{ - fileFilter: `\.(json|yaml|yml|toml|jsonl|ldjson)$`, + fileFilter: `\.(json|yaml|yml|toml|jsonl|ndjson|ldjson)$`, interpretation: build.Auto, loadCfg: &load.Config{DataFiles: true}, } @@ -289,7 +289,7 @@ func runImport(cmd *Command, args []string) (err error) { case "proto": c.fileFilter = `\.proto$` case "json": - c.fileFilter = `\.(json|jsonl|ldjson)$` + c.fileFilter = `\.(json|jsonl|ndjson|ldjson)$` case "yaml": c.fileFilter = `\.(yaml|yml)$` case "toml": diff --git a/cmd/cue/cmd/testdata/script/embed_err.txtar b/cmd/cue/cmd/testdata/script/embed_err.txtar index e9eda77decd..5d2d322e20f 100644 --- a/cmd/cue/cmd/testdata/script/embed_err.txtar +++ b/cmd/cue/cmd/testdata/script/embed_err.txtar @@ -41,9 +41,9 @@ absglob: _ @embed(glob="/x/*.*", type=yaml) doublestar: _ @embed(glob="**/*.json") -stream: _ @embed(file=test.ldjson) +stream: _ @embed(file=test.ndjson) -singlestream: _ @embed(file=single.ldjson) +singlestream: _ @embed(file=single.ndjson) yamlstream: _ @embed(file=stream.yaml) @@ -80,10 +80,10 @@ invalidPattern: _ @embed(glob="x[") -- test.json -- { "x": 34 } --- test.ldjson -- +-- test.ndjson -- { "x": 35 } { "x": 36 } --- single.ldjson -- +-- single.ndjson -- { "x": 37 } -- stream.yaml -- 1 diff --git a/cmd/cue/cmd/testdata/script/encoding_jsonl.txtar b/cmd/cue/cmd/testdata/script/encoding_jsonl.txtar index 0f86248112f..5de6687684b 100644 --- a/cmd/cue/cmd/testdata/script/encoding_jsonl.txtar +++ b/cmd/cue/cmd/testdata/script/encoding_jsonl.txtar @@ -28,7 +28,6 @@ cmp stdout export-one.stdout # Check that `cue import` supports all filenames too, # both by default and when loading JSON only. -# TODO(mvdan): ndjson is not supported here, but it should. # TODO(mvdan): note that `cue import --dry-run` does not work, # so we need to use rm and stderr checks to ensure we create the files we expect. @@ -78,4 +77,5 @@ cmp stderr import.stderr -- import.stderr -- importing into input-jsonl.cue importing into input-ldjson.cue +importing into input-ndjson.cue importing into input-one.cue diff --git a/cue/interpreter/embed/embed.go b/cue/interpreter/embed/embed.go index 90dbb704dcb..cded4f6fe9d 100644 --- a/cue/interpreter/embed/embed.go +++ b/cue/interpreter/embed/embed.go @@ -54,7 +54,7 @@ // # Limitations // // The embed interpreter currently does not support: -// - stream values, such as .ldjson or YAML streams. +// - stream values, such as .ndjson or YAML streams. // - schema-based decoding, such as needed for textproto // // # Example