16
16
17
17
import Debug from "debug"
18
18
import type { Arguments } from "@kui-shell/core"
19
+ import type Options from "./options.js"
19
20
20
- import tailf from "./tailf.js"
21
- import dashboardUI from "./db.js"
21
+ import tailf from "../tailf.js"
22
+ import usage from "../usage.js"
23
+ import dashboardUI from "../db.js"
22
24
import status from "./status/index.js"
23
25
import utilization from "./utilization/index.js"
24
26
25
- import { enterAltBufferMode } from "./term.js"
27
+ import jobIdFrom from "./jobid.js"
28
+ import { enterAltBufferMode } from "../term.js"
29
+ import { KindA , isValidKindA } from "./kinds.js"
26
30
import { SupportedGrid , isSupportedGrid } from "./grids.js"
27
- import { KindA , isValidKindA , validKinds } from "./kinds.js"
28
31
29
32
import type HistoryConfig from "./history.js"
30
- import type { GridSpec } from "../../components/Job/types.js"
31
-
32
- export type Options = Arguments [ "parsedOptions" ] & {
33
- s : number
34
- scale : number
35
-
36
- demo : boolean
37
-
38
- p : string
39
- profile : string
40
- theme : string
41
-
42
- /** Frequency of updates to the timeline, in seconds */
43
- u : number
44
- "update-frequency" : number
45
- }
46
-
47
- export function usage ( cmd : string , extraKinds : string [ ] = [ ] ) {
48
- return `Usage: codeflare ${ cmd } ${ extraKinds . concat ( validKinds ( ) ) . join ( "|" ) } [<jobId>|-N]`
49
- }
50
-
51
- async function lastNJob ( profile : string , N : number ) {
52
- const [ { join } , { readdir, stat } , { Profiles } ] = await Promise . all ( [
53
- import ( "path" ) ,
54
- import ( "fs/promises" ) ,
55
- import ( "madwizard" ) ,
56
- ] )
57
-
58
- const dir = Profiles . guidebookJobDataPath ( { profile } )
59
- const files = await readdir ( dir )
60
- if ( files . length === 0 ) {
61
- throw new Error ( "No jobs available" )
62
- return
63
- }
64
-
65
- const cTimes = await Promise . all ( files . map ( ( _ ) => stat ( join ( dir , _ ) ) . then ( ( _ ) => _ . ctime . getTime ( ) ) ) )
66
- const sorted = files . map ( ( file , idx ) => ( { file, lastM : cTimes [ idx ] } ) ) . sort ( ( a , b ) => b . lastM - a . lastM )
67
-
68
- if ( ! sorted [ N ] ) {
69
- throw new Error ( "Specified historical job not available" )
70
- } else {
71
- return sorted [ N ] . file
72
- }
73
- }
74
-
75
- export async function jobIdFrom ( args : Arguments < Options > , cmd : string , offset = 2 ) {
76
- const profile = args . parsedOptions . p || ( await import ( "madwizard" ) . then ( ( _ ) => _ . Profiles . lastUsed ( ) ) )
77
-
78
- const jobIdFromCommandLine = args . argvNoOptions [ args . argvNoOptions . indexOf ( cmd ) + offset ]
79
- const jobId = / ^ - \d + $ / . test ( jobIdFromCommandLine )
80
- ? await lastNJob ( profile , - parseInt ( jobIdFromCommandLine , 10 ) )
81
- : jobIdFromCommandLine === undefined
82
- ? await lastNJob ( profile , 0 )
83
- : jobIdFromCommandLine
84
-
85
- return { jobId, profile }
86
- }
33
+ import type { GridSpec } from "../../../components/Job/types.js"
87
34
88
35
/** @return grid model for the given `kind` for `jobId` in `profile` */
89
36
async function gridFor (
@@ -104,7 +51,7 @@ async function allGridsFor(
104
51
historyConfig : HistoryConfig ,
105
52
opts : Pick < Options , "demo" | "theme" | "events" >
106
53
) {
107
- const usesGpus = opts . demo || ( await import ( "../env.js" ) . then ( ( _ ) => _ . usesGpus ( profile , jobId ) ) )
54
+ const usesGpus = opts . demo || ( await import ( "../../ env.js" ) . then ( ( _ ) => _ . usesGpus ( profile , jobId ) ) )
108
55
109
56
const all = [
110
57
gridFor ( "status" , profile , jobId , historyConfig , opts ) ,
0 commit comments