cli: add --help to genesis 2D CLI and reject unknown args

Previously unknown flags were silently ignored; now they print usage to
stderr and exit 2, matching the genesis3d behavior.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
saarsena@gmail.com 2026-04-18 13:24:42 -04:00
parent 7a6ae79d01
commit 06ef034866

View file

@ -148,6 +148,26 @@ static void print_summary(uint64_t seed, int depth, const run_stats_t *s) {
s->floor_cells, s->connected, s->unreached); s->floor_cells, s->connected, s->unreached);
} }
static void usage(FILE *f, const char *prog) {
fprintf(f,
"usage: %s [options]\n"
"\n"
"Generates a single Brogue-style 2D level and prints an ASCII map.\n"
"\n"
"options:\n"
" --seed N RNG seed (default 1234)\n"
" --depth N dungeon depth 1..26, biases lakes/machines (default 1)\n"
" --verify assert connectivity after each pipeline stage\n"
" --mark-unreached print '!' on passable cells BFS cannot reach from start\n"
" --verbose stream generator events to stderr\n"
" --quiet suppress ASCII map (summary only)\n"
" --emit=json, --json emit grid JSON to stdout instead of ASCII\n"
" --stress N run N seeds (from --stress-base) and report failures\n"
" --stress-base N starting seed for --stress (default 1)\n"
" -h, --help show this help and exit\n",
prog);
}
static int cmd_stress(int n, uint64_t base_seed, int depth) { static int cmd_stress(int n, uint64_t base_seed, int depth) {
grid_t g; grid_t g;
int failures = 0; int failures = 0;
@ -193,6 +213,13 @@ int main(int argc, char **argv) {
g_mark_unreached = 1; g_mark_unreached = 1;
} else if (!strcmp(argv[i], "--emit=json") || !strcmp(argv[i], "--json")) { } else if (!strcmp(argv[i], "--emit=json") || !strcmp(argv[i], "--json")) {
g_emit_json = 1; g_emit_json = 1;
} else if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) {
usage(stdout, argv[0]);
return 0;
} else {
fprintf(stderr, "unknown arg: %s\n", argv[i]);
usage(stderr, argv[0]);
return 2;
} }
} }