Skip to content

Commit

Permalink
fix: also accept codeflare db
Browse files Browse the repository at this point in the history
  • Loading branch information
starpit committed Mar 31, 2023
1 parent 00d18d4 commit c6c18d9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function enterAltBufferMode() {
console.log("\x1b[?1049h")
}

export function usage(cmd = "dashboard") {
export function usage(cmd: string) {
return `Usage: codeflare ${cmd} ${validKinds().join("|")} [<jobId>|-N]`
}

Expand Down Expand Up @@ -67,7 +67,7 @@ async function lastNJob(profile: string, N: number) {
}
}

export async function jobIdFrom(args: Arguments<Options>, cmd = "dashboard", offset = 2) {
export async function jobIdFrom(args: Arguments<Options>, cmd: string, offset = 2) {
const profile = args.parsedOptions.p || (await import("madwizard").then((_) => _.Profiles.lastUsed()))

const jobIdFromCommandLine = args.argvNoOptions[args.argvNoOptions.indexOf(cmd) + offset]
Expand All @@ -80,19 +80,19 @@ export async function jobIdFrom(args: Arguments<Options>, cmd = "dashboard", off
return { jobId, profile }
}

export default async function dashboard(args: Arguments<Options>) {
export default async function dashboard(args: Arguments<Options>, cmd: "db" | "dashboard") {
const { theme } = args.parsedOptions

const { demo } = args.parsedOptions
const scale = args.parsedOptions.s || 1

const kind = args.argvNoOptions[args.argvNoOptions.indexOf("dashboard") + 1] || "all"
const { jobId, profile } = await jobIdFrom(args)
const kind = args.argvNoOptions[args.argvNoOptions.indexOf(cmd) + 1] || "all"
const { jobId, profile } = await jobIdFrom(args, cmd)

if (!isValidKindA(kind)) {
throw new Error(usage())
throw new Error(usage(cmd))
} else if (!jobId) {
throw new Error(usage())
throw new Error(usage(cmd))
}

const gridFor = async (kind: "status" | "cpu" | "memory"): Promise<GridSpec> => {
Expand All @@ -118,7 +118,7 @@ export default async function dashboard(args: Arguments<Options>) {
const db = dashboardUI(profile, jobId, await gridForA(kind), { scale })

if (!db) {
throw new Error(usage())
throw new Error(usage(cmd))
} else {
const { render } = await import("ink")

Expand Down
10 changes: 6 additions & 4 deletions plugins/plugin-codeflare-dashboard/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ import type { Options as DashboardOptions } from "./controller/dashboard/index.j

/** Register Kui Commands */
export default function registerCodeflareCommands(registrar: Registrar) {
registrar.listen<KResponse, DashboardOptions>(
"/codeflare/dashboard",
(args) => import("./controller/dashboard/index.js").then((_) => _.default(args)),
{ flags }
["db" as const, "dashboard" as const].forEach((db) =>
registrar.listen<KResponse, DashboardOptions>(
`/codeflare/${db}`,
(args) => import("./controller/dashboard/index.js").then((_) => _.default(args, db)),
{ flags }
)
)

registrar.listen<KResponse, DashboardOptions>("/codeflare/dump", (args) =>
Expand Down

0 comments on commit c6c18d9

Please sign in to comment.