Correct CLI: repeatable -data-path flag for dirs, dot path stays positional

This commit is contained in:
lilleman
2026-06-09 00:54:33 +02:00
parent 889b1fbf8b
commit c0eac6538d
3 changed files with 55 additions and 90 deletions
+15 -17
View File
@@ -24,27 +24,25 @@ lacked the locale coverage and format control we needed.
## CLI
Install the `fakes` command, then give it one or more `-path` flags and one or
more data directories — it prints one value per path to stdout. Each dot segment
descends one level: folders, then the category (a JSON file), then fields inside it.
Install the `fakes` command, then give it one or more `-data-path` directories
and a path — it prints one value to stdout. Each dot segment descends one level:
folders, then the category (a JSON file), then fields inside it.
```sh
go install github.com/Timewave-AB/fakes/cmd/fakes@latest
fakes -path person ./data/sv_SE # Sara Eriksson
fakes -path person.last ./data/sv_SE # Eriksson (dotted path into a category)
fakes -path sv_SE.person ./data # point at the tree; the folder is a segment
fakes -path person -path address ./data/sv_SE # several paths, one value each
fakes -path word ./data/sv_SE ./mydata # layer dirs; the last wins a name clash
fakes -seed 42 -path address ./data/sv_SE
fakes -repeat 3 -path person ./data/sv_SE # three values, one per line
fakes -repeat 3 -separator ', ' -path word ./data/sv_SE # nät, barn, sol
fakes -data-path ./data/sv_SE person # Sara Eriksson
fakes -data-path ./data/sv_SE person.last # Eriksson (dotted path into a category)
fakes -data-path ./data sv_SE.person # point at the tree; the folder is a segment
fakes -data-path ./data/sv_SE -data-path ./mydata word # layer dirs; the last wins a name clash
fakes -seed 42 -data-path ./data/sv_SE address
fakes -repeat 3 -data-path ./data/sv_SE person # three values, one per line
fakes -repeat 3 -separator ', ' -data-path ./data/sv_SE word # nät, barn, sol
```
`-path` is repeatable, and flags come before the data directories. `-repeat N`
renders each path N times — every render an independent draw — and all emitted
values (`repeat` × paths) are joined by `-separator` (default a newline, so
values land one per line).
`-data-path` is repeatable (last wins a name clash) and the path comes last, after
the flags. `-repeat N` renders the path N times — each an independent draw — joined
by `-separator` (default a newline, so values land one per line).
Without installing, run it from a checkout with `go run ./cmd/fakes …`. Exit
codes: `0` success, `1` runtime error (missing dir, unknown path), `2` misuse.
@@ -72,7 +70,7 @@ the `),(` separator; the outer `V#ALUES(…)` wraps that into one valid row list
letter token — see [Data format](#data-format).)
```sh
fakes -seed 1 -path sql ./data/sv_SE
fakes -seed 1 -data-path ./data/sv_SE sql
# INSERT INTO users VALUES('zoom'),('wahoo'),('blip');
```
@@ -80,7 +78,7 @@ Raise the template's `repeat` for more rows per statement; use the CLI's
`-repeat` for more statements — together they build a whole seed file:
```sh
fakes -repeat 100 -path sql ./data/sv_SE > seed.sql
fakes -repeat 100 -data-path ./data/sv_SE sql > seed.sql
```
## Library