tweak help and commands
This commit is contained in:
parent
415cbd0ccd
commit
ebfddbb278
|
|
@ -1,23 +1,19 @@
|
|||
/// <reference lib="dom" />
|
||||
// Print all the commands.
|
||||
// Print all the commands, or a subset.
|
||||
|
||||
import { commands } from "@/js/commands"
|
||||
import { commands } from "@/commands"
|
||||
|
||||
export default function (prefix?: string) {
|
||||
let cmds = prefix ? matchingCommands(prefix) : commands
|
||||
export default async function (prefix?: string) {
|
||||
let cmds = prefix ? await matchingCommands(prefix) : Object.keys(await commands())
|
||||
|
||||
return { html: "<div>" + Object.keys(cmds).map(cmd => `<a href="#help ${cmd}">${cmd}</a>`).join("") + "</div>" }
|
||||
return { html: "<div>" + cmds.map(cmd => `<a href="#help ${cmd}">${cmd}</a>`).join("") + "</div>" }
|
||||
}
|
||||
|
||||
|
||||
function matchingCommands(cmd: string): string {
|
||||
async function matchingCommands(cmd: string): Promise<string[]> {
|
||||
let matched: string[] = []
|
||||
console.log(Object.keys(commands))
|
||||
for (const command of Object.keys(commands)) {
|
||||
console.log("cmd->", command)
|
||||
|
||||
for (const command of Object.keys(await commands()))
|
||||
if (command.startsWith(cmd)) matched.push(command)
|
||||
}
|
||||
|
||||
|
||||
return matched.join(" ")
|
||||
return matched
|
||||
}
|
||||
17
bin/help.ts
17
bin/help.ts
|
|
@ -2,13 +2,15 @@
|
|||
//
|
||||
// (Hopefully.)
|
||||
|
||||
import { commandPath, commands } from "@/commands"
|
||||
import { commandPath } from "@/commands"
|
||||
import type { CommandOutput } from "@/shared/types"
|
||||
import commands from "./commands"
|
||||
|
||||
export default async function (cmd: string): Promise<string> {
|
||||
export default async function (cmd: string): Promise<CommandOutput> {
|
||||
if (!cmd) return "usage: help <command>"
|
||||
|
||||
const path = commandPath(cmd)
|
||||
if (!path) { return matchingCommands(cmd) }
|
||||
if (!path) return await commands(cmd)
|
||||
|
||||
const code = (await Bun.file(path).text()).split("\n")
|
||||
let docs = []
|
||||
|
|
@ -26,12 +28,3 @@ export default async function (cmd: string): Promise<string> {
|
|||
|
||||
return docs.join("\n")
|
||||
}
|
||||
|
||||
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.join(" ")
|
||||
}
|
||||
|
|
@ -1,3 +1,5 @@
|
|||
// Print information about the current session.
|
||||
|
||||
import { sessionGet } from "@/session"
|
||||
import { highlightToHTML } from "../lib/highlight"
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user