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.)
|
// (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>"
|
if (!cmd) return "usage: help <command>"
|
||||||
|
|
||||||
const path = commandPath(cmd)
|
const path = commandPath(cmd)
|
||||||
if (!path) throw `${cmd} not found`
|
if (!path) { return matchingCommands(cmd) }
|
||||||
|
|
||||||
const code = (await Bun.file(path).text()).split("\n")
|
const code = (await Bun.file(path).text()).split("\n")
|
||||||
let docs = []
|
let docs = []
|
||||||
|
|
@ -26,3 +26,12 @@ export default async function (cmd: string) {
|
||||||
|
|
||||||
return docs.join("\n")
|
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