// Print all the commands, or a subset.

import { commands } from "@/commands"

export default async function (prefix?: string) {
    let cmds = prefix ? await matchingCommands(prefix) : Object.keys(await commands())

    return { html: "<div>" + cmds.map(cmd => `<a href="#help ${cmd}">${cmd}</a>`).join("") + "</div>" }
}


async function matchingCommands(cmd: string): Promise<string[]> {
    let matched: string[] = []

    for (const command of Object.keys(await commands()))
        if (command.startsWith(cmd)) matched.push(command)

    return matched
}