fix: change URL flag from boolean to string type for proper URL passing

This commit is contained in:
mitchell 2026-05-14 04:34:01 -04:00
parent 7441a9fc19
commit 03dee78e0c

20
tts.ts
View file

@ -13,8 +13,8 @@ const { values: args } = parseArgs({
options: {
wait: { type: "boolean" },
w: { type: "boolean" },
url: { type: "boolean" },
u: { type: "boolean" },
url: { type: "string" },
u: { type: "string" },
},
strict: true,
allowPositionals: true,
@ -22,23 +22,23 @@ const { values: args } = parseArgs({
const wait = args.wait ?? args.w;
const url = args.url ?? args.u;
let text = await Bun.stdin.text();
let input = url ? url : await Bun.stdin.text();
if (url) {
const result = await fetch(text.trim());
const window = new Window({ url: text.trim() });
if (url !== undefined) {
const result = await fetch(input.trim());
const window = new Window({ url: input.trim() });
const doc = window.document;
doc.write(await result.text());
await window.happyDOM.waitUntilComplete();
const readable = new Readability(doc).parse();
if (readable?.textContent) text = readable.textContent;
if (text.trim() === result.url) {
if (readable?.textContent) input = readable.textContent;
if (input.trim() === result.url) {
console.error("Unable to read web page.");
process.exit(1);
}
}
if (!text) {
if (!input) {
console.error("No input given.");
process.exit(1);
}
@ -59,7 +59,7 @@ console.log(
const koko = Bun.spawn({
cmd: ["uv", "run", "--", "python", "-u", "main.py"],
cwd,
stdin: Buffer.from(text),
stdin: Buffer.from(input),
stdout: "pipe",
stderr: "inherit",
});