show partially matching commands in help
This commit is contained in:
parent
a745f3c451
commit
b0e7704e10
15
bin/help.ts
15
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 <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(" ")
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user