From 5e6330c75b24d796ebac38dbe278ddc167496c32 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Sun, 11 Oct 2026 23:29:23 +0200 Subject: [PATCH] Answer product-owner round 1: the hint for an empty stdin points to --list, the help's examples are templates only, the README's record id is an integer, and a test over an indexed module renders each path --- README.md | 5 +++-- cli/cli.go | 3 +-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index da32a5b..aa29fb1 100644 --- a/README.md +++ b/README.md @@ -352,7 +352,7 @@ v = t.Fake() // render many times, r, err := f.FakeRecord("users") // one record: each field a column s := r.JSON() // {"first":"Ada","last":"Lovelace"} r, err = f.FakeRecordTemplate(`{"format":"{x}","x":["a","b"]}`) // compile + render inline -rt, err := f.NewRecordTemplate(`{"format":"","id":"{seq(users)}"}`) // compile a record once +rt, err := f.NewRecordTemplate(`{"format":"","id":{"format":"{seq(users)}","datatype":"integer"}}`) // compile once r = rt.Fake() // render a row; loop this for bulk output err = f.FakeStruct(&user) // fill a struct's fake:"…" tagged fields ok, err := fejkdata.IsTemplate(arg) // an inline template by its shape, else a path @@ -459,7 +459,8 @@ func main() { os.Exit(cli.Main(append(data.Modules(), mydata)...)) } The embed's folders are the paths: `//go:embed acme` serves `acme/customer.json` as `{/acme.customer}`. Add `*.tsv` to the embed where your data holds a table. The CLI loads its data when it runs, so a test calling `fejkdata.New(fejkdata.WithDataFS(...))` over the -same modules catches broken data at `go test`. The CLI takes `fejkdata`'s flags +same modules, rendering each path once where a module carries an index, catches broken +data at `go test`. The CLI takes `fejkdata`'s flags and exit codes, and names itself by the file it runs from in its help and errors. `--no-shipped-data` leaves out the modules passed to `Main`, and `--version` prints your module's version beside the fejkdata version it is built with. diff --git a/cli/cli.go b/cli/cli.go index 47bbba5..8b37781 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -29,7 +29,6 @@ COMMAND reads one template from stdin and renders it: echo 'id: {int(1,999)}' | COMMAND echo '{"format":"{x}","x":["bosse","lina"]}' | COMMAND - COMMAND --list # the paths a {/path} reference reads COMMAND < template.txt COMMAND <<'EOF' @@ -630,7 +629,7 @@ func run(name string, modules []fs.FS, args []string, stdin io.Reader, stdout, s func readStdin(stdin io.Reader, name string) (input, error) { if stdin == nil { - return input{}, inputError{fmt.Errorf("the template comes from stdin, and nothing is piped in: %s", pipeHint(name))} + return input{}, inputError{fmt.Errorf("the template comes from stdin, and nothing is piped in: %s; %s --list prints the paths a {/path} reference reads", pipeHint(name), name)} } raw, err := io.ReadAll(stdin) if err != nil {