Make great documentation goal 1.2, and plan the README's reorganisation and the nested-template gaps #33

Open
lilleman wants to merge 966 commits from worktree-todo-relative-dates-exact-counts into main
4 changed files with 9 additions and 11 deletions
Showing only changes of commit 48e2b1ce9f - Show all commits
+5 -6
View File
@@ -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 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 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; 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 42 or true alone is a format string, printed as written. An empty or blank stdin is a
renders as it is. A format string like any other, and renders as sent. A quoted heredoc, <<'EOF', passes $,
quoted heredoc, <<'EOF', passes $, a backslash or a quote as written. a backslash or a quote as written.
With --format json, ndjson, csv or sql the template must be a record — a JSON 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}: template whose fields are its columns, or a lone reference such as {/sv_SE.person}:
@@ -468,9 +468,8 @@ type input struct {
record string record string
} }
// parseInput reads stdin as the template, and as a record where it is a lone reference: JSON // parseInput keeps stdin whole as the template, and names a record where stdin is a lone
// with the whitespace around it dropped, else a format string with one newline ending it // reference once JSON's surrounding whitespace, or one final newline, is cut.
// allowed.
func parseInput(raw string) input { func parseInput(raw string) input {
trimmed := strings.Trim(raw, jsonSpace) trimmed := strings.Trim(raw, jsonSpace)
text := raw text := raw
+1 -2
View File
@@ -20,8 +20,7 @@ const (
DataTypeBoolean DataType = datatype.Boolean DataTypeBoolean DataType = datatype.Boolean
) )
// datatypeOf reads a template's "datatype", nil where it carries none or sits outside a column, // datatypeOf reads a template's "datatype", nil where it carries none or sits outside a column.
// where no datatype applies.
func datatypeOf(m map[string]any, pos position) (*DataType, error) { func datatypeOf(m map[string]any, pos position) (*DataType, error) {
v, ok := m["datatype"] v, ok := m["datatype"]
if !ok { if !ok {
+2 -2
View File
@@ -103,7 +103,7 @@ func (t *Table[O]) parseRows(data string) error {
t.col[name] = i t.col[name] = i
} }
if header == data { 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) m := len(t.header)
t.cells = make([]string, 0, m*(strings.Count(rest, "\n")+1)) 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 // 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 { func (t *Table[O]) bindOptions() error {
o := t.options o := t.options
for _, opt := range []struct { for _, opt := range []struct {
+1 -1
View File
@@ -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 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 // jsonKind names the kind of a JSON value an option cannot take, in the data format's own