show partially matching commands in help

This commit is contained in:
Chris Wanstrath 2025-10-07 10:42:55 -07:00
parent a745f3c451
commit b0e7704e10

View File

@ -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 <command>"
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(" ")
}