From 0de54c3b1567a2606a5df8002c1a98f32ec1a675 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Wed, 7 Oct 2026 21:43:04 +0200 Subject: [PATCH] Answer architecture round 4, stability round 3, product-owner round 3 and prose round 2: stdin trims JSON's own whitespace around any JSON value, the padded-JSON title names NewTemplate and the CLI, the JSON examples hold no backslash for echo, an argument's example is built only from a template or a valid reference and shell-quoted, the text scope of adding nothing, blank stdin, and the stdin decision in four paragraphs --- AGENTS.md | 2 +- CHANGELOG.md | 4 ++-- README.md | 10 +++++---- cmd/fejkdata/main.go | 45 ++++++++++++++++++++++----------------- cmd/fejkdata/main_test.go | 5 ++++- docs/decisions.md | 44 ++++++++++++++++++++++---------------- todo.md | 8 +++---- 7 files changed, 69 insertions(+), 49 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 171950d..491079d 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -42,7 +42,7 @@ In [docs/decisions.md](docs/decisions.md): - A struct tag is a template by its shape - The CLI renders exactly the template on its stdin, and adds nothing - A template that does not compile is misuse (exit 2), including a reference that resolves to nothing, save a lone reference under the CLI's `--format` until item 129 -- A padded JSON template is rejected, not trimmed +- `NewTemplate` rejects a padded JSON template, and the CLI's stdin drops the whitespace around one - `FakeTemplate` and `NewTemplate` both stay - The shipped data is embedded, not discovered - With only the shipped set, a category loads on the first call reaching it; beside a `--data-path`, every category loads in `New` diff --git a/CHANGELOG.md b/CHANGELOG.md index 6508fe9..d05bf4c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,10 +28,10 @@ replacement, and each removed path, column or flag. under [Names](README.md#names). - First release: the CLI, the library and the shipped data set. - The CLI renders exactly the template on its stdin, `echo '{/sv_SE.person} hihi' | - fejkdata`, and adds nothing: `echo`'s newline ends the render, and `--separator` + fejkdata`, and adds nothing to text: `echo`'s newline ends the render, and `--separator` defaults to empty. Whitespace around a JSON template is dropped. A lone reference, `{/users}`, is the record `users` under `--format`. An argument other than a flag, an - empty stdin, or nothing piped in, exits 2. + empty or blank stdin, or nothing piped in, exits 2. - Table categories: a category JSON naming a `rows` TSV beside it, with the options `key`, `name`, `weight` and `parent`; a path selects a row by key or name, `misc.territory[SE]`, and descends to a linked table by name, one path drawing each diff --git a/README.md b/README.md index 80bb93c..edff22a 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ echo '{/misc.territory[SE].capital}' | fejkdata # Stockholm — a table echo '{/geo.SE.locality[Lund].street}' | fejkdata # Fjelievägen — a linked table, drawn inside the row echo '{/sv_SE.word}' | fejkdata --data-path ./mydata # layer a directory over the shipped data fejkdata --no-shipped-data -d ./mydata --list # only your data -echo '{"format":"name: {x}\n","x":["bosse","lina"]}' | fejkdata # name: bosse or name: lina +echo '{"format":"name: {x}","x":["bosse","lina"]}' | fejkdata # name: bosse or name: lina fejkdata < template.txt # a template kept in a file fejkdata <<'EOF' # born 2003-11-27 — a quoted heredoc passes ', $ and \ as written born {date(1990-01-01,2010-12-31,'2006-01-02')} @@ -38,10 +38,12 @@ inside one: each dot segment descends one level — folders, then the category ( file), then fields — and `[SE]` after a [table](#table) selects its row. `--list` prints these paths; a template reads one as `{/path}`. -What you send is what renders, and fejkdata adds nothing. A format string keeps every +In text, what you send is what renders, and fejkdata adds nothing. A format string keeps every byte, so `echo`, a file or a heredoc ends each render with its newline, and `printf '%s'` sends none; `-n` joins renders with `--separator`, empty by default. A JSON template is -its JSON, the whitespace around it dropped, so `42`, `true` or `null` alone is refused. A +an object, array or string, and the whitespace around it is dropped; `42`, `true` or +`null` alone is refused. A JSON template that should end each render in a newline writes +`\n` in its format, from a quoted heredoc or a file. A lone reference, one `{/…}` and nothing else, is the record it names under `--format`, one newline after it allowed. Some shells' `echo` reads a backslash as an escape, so pipe a template holding one from a quoted heredoc or a file. The rest of stdin's rules are under @@ -63,7 +65,7 @@ template holding one from a quoted heredoc or a file. The rest of stdin's rules follows (`-n3`, `-n 3`) and short flags bundle (`-hn 3`) — see [Decisions](docs/decisions.md#flags-follow-getopt_long); flags go anywhere, `--` ends them. Exit codes: `0` success, `1` runtime error (missing dir, a lone reference to nothing under `--format`), `2` misuse — a bad flag, an argument -other than a flag, an empty or unreadable stdin, nothing piped in, or a +other than a flag, an empty, blank or unreadable stdin, nothing piped in, or a template that does not compile. From a checkout: `go run ./cmd/fejkdata …`. diff --git a/cmd/fejkdata/main.go b/cmd/fejkdata/main.go index f2d6048..9ab48d7 100644 --- a/cmd/fejkdata/main.go +++ b/cmd/fejkdata/main.go @@ -28,7 +28,7 @@ const usage = `Usage: