change stdin api for better testability

This commit is contained in:
JOLIMAITRE Matthieu 2024-06-03 05:17:38 +02:00
parent 1059391e3b
commit 334c7361fc
13 changed files with 312 additions and 44 deletions

View file

@ -1,6 +1,13 @@
#!/usr/bin/env -S deno run --allow-read
#!/usr/bin/env -S deno run -A --unstable-temporal
import { Command } from "https://deno.land/x/cliffy@v1.0.0-rc.4/command/mod.ts";
import {
report,
section,
startup,
tip,
top,
} from "https://git.barnulf.net/mb/profiterole/raw/commit/02d19fce2a0878abd176801cf8f2a663f6db6c16/mod.ts";
import {
Dict,
@ -14,7 +21,7 @@ import {
VerboseLogging,
} from "./lib/lib.ts";
import { francais } from "../data/data.ts";
import { gutenberg } from "../data/data.ts";
import { last } from "./lib/utils.ts";
async function main() {
@ -51,8 +58,10 @@ async function main() {
.parse(Deno.args);
const length = args.options.length ?? args.options.target?.length ?? 6;
let dict = Dict.from_lines(francais, length);
tip("dict");
let dict = Dict.from_lines(gutenberg, length);
if (args.options.file !== undefined) dict = await Dict.from_text_file(args.options.file, length);
top("dict");
const guesser = guessers.get(args.options.guesser)!(dict);
let game = Simulator.from_dict_rand(dict);
@ -64,6 +73,8 @@ async function main() {
const result = last(await runner.play_all());
if (result === undefined) Deno.exit(1);
if (result.result.kind === "failure") Deno.exit(1);
report();
}
function validate_target(target: string, length: number) {