From b0e7704e10561282f8163e582694f9be2a40937b Mon Sep 17 00:00:00 2001 From: Chris Wanstrath <2+defunkt@users.noreply.github.com> Date: Tue, 7 Oct 2025 10:42:55 -0700 Subject: [PATCH] show partially matching commands in help --- bin/help.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/bin/help.ts b/bin/help.ts index f5c6862..8e213dc 100644 --- a/bin/help.ts +++ b/bin/help.ts @@ -2,13 +2,13 @@ // // (Hopefully.) -import { commandPath } from "@/commands" +import { commandPath, commands } from "@/commands" -export default async function (cmd: string) { +export default async function (cmd: string): string { if (!cmd) return "usage: help " const path = commandPath(cmd) - if (!path) throw `${cmd} not found` + if (!path) { return matchingCommands(cmd) } const code = (await Bun.file(path).text()).split("\n") let docs = [] @@ -25,4 +25,13 @@ export default async function (cmd: string) { } return docs.join("\n") +} + +async function matchingCommands(cmd: string): string { + let matched: string[] = [] + for (const command of await commands()) { + if (command.startsWith(cmd)) matched.push(command) + } + + return matched.join(" ") } \ No newline at end of file