⚙️ Enhance script functionality with timeout settings, improved command handling, and updated dependencies

This commit is contained in:
2026-04-12 22:53:09 +08:00
parent ff49c530b7
commit f49c8890c8
3 changed files with 32 additions and 16 deletions

View File

@@ -1,8 +1,14 @@
#!/usr/bin/env runts -- --allow-all
import {parseArgs} from "jsr:@std/cli/parse-args";
import {execCommandShell, exit, log, ProcessBar, term,} from "https://script.hatter.ink/@67/deno-commons-mod.ts";
import {howto} from "https://script.hatter.ink/@1/deno-ai-mod.ts";
import { parseArgs } from "jsr:@std/cli/parse-args";
import {
execCommandShell,
exit,
log,
ProcessBar,
term,
} from "https://script.hatter.ink/@67/deno-commons-mod.ts";
import { howto } from "https://script.hatter.ink/@2/deno-ai-mod.ts";
async function main() {
const flags = parseArgs(Deno.args, {
@@ -42,10 +48,14 @@ howto.ts [-N|--no-exec] 'MESSAGE' - generate command line for MESSAGE
if (!noExec) {
try {
const commandLines = extractCommand(summary);
console.log(
"Found command lines: ",
term.auto(`[green][[[${commandLines}]]][/]`),
);
if (commandLines.length == 1) {
log.success(
"Found command line: ",
term.auto(`[green][[[${commandLines}]]][/]`),
);
} else {
log.success(`Found ${commandLines.length} commands`);
}
if (commandLines.length == 1) {
if (confirm("Execute this command?")) {
@@ -57,8 +67,11 @@ howto.ts [-N|--no-exec] 'MESSAGE' - generate command line for MESSAGE
);
}
} else {
const colors = ["red", "green", "blue"];
for (const [i, command] of commandLines.entries()) {
console.log(`# ${i}: ${command}`);
console.log(term.auto(
`[${colors[i % 3]}][[[# ${i}: ${command}]]][/]`,
));
}
const selectCommandLineIndex = parseInt(
prompt(
@@ -92,15 +105,16 @@ howto.ts [-N|--no-exec] 'MESSAGE' - generate command line for MESSAGE
function extractCommand(summary: string): string[] {
const lines = summary.split(/\r?\n/);
const codeBlocks: string[] = [];
const sb: string[] = [];
let codeBlock: string[] = [];
let inCode = false;
for (const line of lines) {
if (inCode) {
if (line.startsWith("```")) {
codeBlocks.push(sb.join("\n"));
codeBlocks.push(codeBlock.join("\n"));
codeBlock = [];
inCode = false;
} else {
sb.push(line);
codeBlock.push(line);
}
} else if (line.startsWith("```")) {
inCode = true;
@@ -117,5 +131,5 @@ main().catch((err) => {
process.exit(0);
}).then(() => process.exit(0));
// @SCRIPT-SIGNATURE-V1: yk-r1.ES256.20260412T223617+08:00.MEUCIQDnSaL6GY90yaRpt8ma
// aWHXc9cHuVgrg7BrziUQzMamLQIgflN7/NxONwn0iqrPiCdOlbAcWBdVw47XlyU5bwNgA20=
// @SCRIPT-SIGNATURE-V1: yk-r1.ES256.20260412T225301+08:00.MEQCIEPTb4Mwqih4QKV7EULz
// SAoBxv7KfLZjH14w5EQrdOKHAiAkl/cxcehBt/Lot9ZLfYsJQfPSzZKBkDwy/RWjxsjyhQ==