commit 4069bd03dbc26c37a722f1ef4b6e0019b8aa2fe7
parent 4aded31daa4d5a7589746676a3aab94072b7175d
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Tue, 17 Nov 2026 18:19:25 -0500
umtool reads: --only that names nothing is refused; --one is the queue step's form; no Object property as a subcommand (review 2, N3, N6, N8, question a)
N3: --only with no value, "" or "," was null, so reread, pick and replace ran over every read; it is now a
usage error (exit 2), and a valued flag followed by a flag has no value rather than eating it. N6: --one
needs --only and refuses --dry-run, --wait, --stale, --timeout. N8: the flag table is looked up with
Object.hasOwn. reread --one --json prints one JSON document on stdout; readsCommand takes the tts stub
for it.
Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat:
1 file changed, 26 insertions(+), 8 deletions(-)
diff --git a/umtool/lib/report/readsCli.mjs b/umtool/lib/report/readsCli.mjs
@@ -60,9 +60,10 @@ const VALUED = new Set(["--find", "--character", "--only", "--one", "--retry", "
/**
* `umtool reads …`
* @param {string[]} args
- * @param {{ root?: string, out?: (s: string) => void, err?: (s: string) => void, sleep?: (ms: number) => Promise<void>, queueDir?: string }} [o]
+ * @param {{ root?: string, out?: (s: string) => void, err?: (s: string) => void, sleep?: (ms: number) => Promise<void>, queueDir?: string, tts?: Function | null }} [o]
+ * `tts`: the editor's tts op as a test hands it (postsCommand's), for `reread --one`
*/
-export async function readsCommand(args, { root = REPORTS_ROOT, out = (s) => console.log(s), err = (s) => console.error(s), sleep = (ms) => new Promise((r) => setTimeout(r, ms)), queueDir = undefined } = {}) {
+export async function readsCommand(args, { root = REPORTS_ROOT, out = (s) => console.log(s), err = (s) => console.error(s), sleep = (ms) => new Promise((r) => setTimeout(r, ms)), queueDir = undefined, tts = null } = {}) {
const flags = new Map();
const words = [];
let ended = false;
@@ -71,13 +72,24 @@ export async function readsCommand(args, { root = REPORTS_ROOT, out = (s) => con
// `--`: every word after it is a word (a `to` that starts with dashes), never a flag.
if (!ended && a === "--") ended = true;
else if (!ended && VALUED.has(a)) {
- flags.set(a, args[i + 1] ?? "");
- i += 1;
+ // A valued flag followed by another flag (or nothing) has no value: "" (refused where it matters, never eaten).
+ const v = args[i + 1];
+ if (v === undefined || (v.startsWith("--") && v !== "--")) flags.set(a, "");
+ else {
+ flags.set(a, v);
+ i += 1;
+ }
} else if (!ended && a.startsWith("--")) flags.set(a, true);
else words.push(a);
}
const str = (k) => (typeof flags.get(k) === "string" ? flags.get(k) : null);
- const ids = (k) => (str(k) ?? "").split(",").map((x) => x.trim()).filter(Boolean);
+ // A list of ids: none when the flag is absent; refused when it is given and names none ("", ",", no value) -- an
+ // `--only` that names nothing never widens to every read.
+ const ids = (k) => {
+ const list = (str(k) ?? "").split(",").map((x) => x.trim()).filter(Boolean);
+ if (flags.has(k) && !list.length) throw new ReadsUsage(`${k} names no read (give the read ids, comma separated)`);
+ return list;
+ };
const json = flags.has("--json");
const [projectArg, sub = null, ...rest] = words;
if (!projectArg || flags.has("--help")) {
@@ -87,7 +99,7 @@ export async function readsCommand(args, { root = REPORTS_ROOT, out = (s) => con
const say = (j, text) => out(json ? JSON.stringify(j, null, 2) : text);
try {
// Each subcommand's own flags; any other is refused (never ignored: `undo --dry-run` must not undo).
- const allowed = FLAGS_OF[sub ?? ""];
+ const allowed = Object.hasOwn(FLAGS_OF, sub ?? "") ? FLAGS_OF[sub ?? ""] : null;
if (!allowed) throw new ReadsUsage(`reads: replace, undo, reread, queue or pick (not ${sub}); none lists the reads`);
const unknown = [...flags.keys()].filter((f) => f !== "--json" && f !== "--help" && !allowed.includes(f));
if (unknown.length) throw new ReadsUsage(`${unknown.join(", ")}: not a flag of \`reads <p>${sub ? ` ${sub}` : ""}\` (its flags: ${allowed.join(" ") || "none"}; -- ends the flags)`);
@@ -159,8 +171,14 @@ export async function readsCommand(args, { root = REPORTS_ROOT, out = (s) => con
return 0;
}
const Q = await import("./readsQueue.mjs");
- if (sub === "reread" && str("--one") !== null) {
- const res = await Q.runOneItem(project, str("--one"), ids("--only"), { reportsRoot: root, log: (s) => !json && out(s) });
+ if (sub === "reread" && flags.has("--one")) {
+ // THE QUEUE STEP's FORM (the app runs it): one item, the reads it names -- never a dry run, a wait or every stale.
+ if (!str("--one")) throw new ReadsUsage("--one names the item (the queue's step: reread --one <item> --only <ids>)");
+ const clash = ["--dry-run", "--wait", "--stale", "--timeout"].filter((f) => flags.has(f));
+ if (clash.length) throw new ReadsUsage(`--one is the queue's step: it takes no ${clash.join(", ")} (umtool reads <p> reread [--only …] [--dry-run] [--wait] queues)`);
+ if (!flags.has("--only")) throw new ReadsUsage("--one takes --only <ids> (the reads its step was queued for)");
+ // With --json, stdout is one JSON document: the re-read command's own words go to stderr.
+ const res = await Q.runOneItem(project, str("--one"), ids("--only"), { reportsRoot: root, log: (s) => (json ? err(s) : out(s)), quiet: json ? { out: err, err } : null, ...(tts ? { tts } : {}) });
if (json) out(JSON.stringify({ ok: res.code === 0, item: str("--one"), argv: res.argv, reads: res.reads, code: res.code }, null, 2));
return res.code;
}