From 48e2b1ce9f456e079f3e8dd0f1e751659fcb1398 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Thu, 8 Oct 2026 12:33:06 +0200 Subject: [PATCH] Reword the bindOptions, parseInput and datatypeOf comments, the --help paragraph on blank stdin, and the empty-table and no-datatype errors --- cmd/fejkdata/main.go | 11 +++++------ datatype.go | 3 +-- internal/rows/rows.go | 4 ++-- node.go | 2 +- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/cmd/fejkdata/main.go b/cmd/fejkdata/main.go index 57522b2..77b9c27 100644 --- a/cmd/fejkdata/main.go +++ b/cmd/fejkdata/main.go @@ -46,9 +46,9 @@ Under --format text, the default, what you send is what renders, and fejkdata ad nothing: a format string keeps every byte, so echo's newline ends each render, and printf '%s' sends none. -n joins renders with --separator, empty by default. A JSON object, array or string drops the whitespace around it, and null alone renders nothing; -42 or true alone is a format string, printed as written. An empty or blank stdin -renders as it is. A -quoted heredoc, <<'EOF', passes $, a backslash or a quote as written. +42 or true alone is a format string, printed as written. An empty or blank stdin is a +format string like any other, and renders as sent. A quoted heredoc, <<'EOF', passes $, +a backslash or a quote as written. With --format json, ndjson, csv or sql the template must be a record — a JSON template whose fields are its columns, or a lone reference such as {/sv_SE.person}: @@ -468,9 +468,8 @@ type input struct { record string } -// parseInput reads stdin as the template, and as a record where it is a lone reference: JSON -// with the whitespace around it dropped, else a format string with one newline ending it -// allowed. +// parseInput keeps stdin whole as the template, and names a record where stdin is a lone +// reference once JSON's surrounding whitespace, or one final newline, is cut. func parseInput(raw string) input { trimmed := strings.Trim(raw, jsonSpace) text := raw diff --git a/datatype.go b/datatype.go index cb8924b..9f72817 100644 --- a/datatype.go +++ b/datatype.go @@ -20,8 +20,7 @@ const ( DataTypeBoolean DataType = datatype.Boolean ) -// datatypeOf reads a template's "datatype", nil where it carries none or sits outside a column, -// where no datatype applies. +// datatypeOf reads a template's "datatype", nil where it carries none or sits outside a column. func datatypeOf(m map[string]any, pos position) (*DataType, error) { v, ok := m["datatype"] if !ok { diff --git a/internal/rows/rows.go b/internal/rows/rows.go index aa00b73..435dec0 100644 --- a/internal/rows/rows.go +++ b/internal/rows/rows.go @@ -103,7 +103,7 @@ func (t *Table[O]) parseRows(data string) error { t.col[name] = i } if header == data { - return fmt.Errorf("has no rows below its header; a table is at least one row") + return fmt.Errorf("has no rows below its header; a table holds at least one row") } m := len(t.header) t.cells = make([]string, 0, m*(strings.Count(rest, "\n")+1)) @@ -139,7 +139,7 @@ func (t *Table[O]) appendRow(row string, line int) error { } // bindOptions resolves each option to its column, and proves what the options claim of the cells: a -// key is unique, a weight a positive number. +// key is unique, and a weight is a number of 0 or more. func (t *Table[O]) bindOptions() error { o := t.options for _, opt := range []struct { diff --git a/node.go b/node.go index 09efe82..8e7b40b 100644 --- a/node.go +++ b/node.go @@ -172,7 +172,7 @@ func typedOrText(text string, ds ...DataType) error { return fmt.Errorf(`%s in a record column could be text or a value of datatype %s; write %q for text, or {"format":%q,"datatype":%q}`, text, d, text, text, d) } } - return fmt.Errorf(`%s in a record column could be text or a typed value, though no datatype holds it; write %q for text`, text, text) + return fmt.Errorf(`%s in a record column fits no datatype; write %q for text`, text, text) } // jsonKind names the kind of a JSON value an option cannot take, in the data format's own