@@ -18,35 +18,65 @@ import { Arguments } from "@kui-shell/core"
1818
1919import { pathsFor } from "./dashboard/tailf.js"
2020import { isValidKind } from "./dashboard/kinds.js"
21- import { Options , jobIdFrom , usage } from "./dashboard/index.js"
21+ import { Options as DashboardOptions , jobIdFrom , usage as dbUsage } from "./dashboard/index.js"
22+
23+ export type Options = DashboardOptions & {
24+ f : boolean
25+ follow : boolean
26+ }
27+
28+ export const flags = {
29+ boolean : [ "follow" ] ,
30+ alias : { follow : [ "f" ] } ,
31+ }
32+
33+ function usage ( ) {
34+ return dbUsage ( "dump" ) + " [-f/--follow]"
35+ }
2236
2337export default async function dump ( args : Arguments < Options > ) {
2438 const kind = args . argvNoOptions [ args . argvNoOptions . indexOf ( "dump" ) + 1 ]
2539 const { jobId, profile } = await jobIdFrom ( args , "dump" )
2640
2741 if ( ! isValidKind ( kind ) ) {
28- throw new Error ( usage ( "dump" ) )
42+ throw new Error ( usage ( ) )
2943 } else if ( ! jobId ) {
30- throw new Error ( usage ( "dump" ) )
44+ throw new Error ( usage ( ) )
3145 }
3246
33- const { createReadStream } = await import ( "fs" )
34- await Promise . all (
35- (
36- await pathsFor ( kind , profile , jobId )
37- ) . map (
38- ( filepath ) =>
39- new Promise ( ( resolve , reject ) => {
40- try {
41- const rs = createReadStream ( filepath )
42- rs . on ( "close" , resolve )
43- rs . pipe ( process . stdout )
44- } catch ( err ) {
45- reject ( err )
46- }
47- } )
47+ if ( ! args . parsedOptions . f ) {
48+ const { createReadStream } = await import ( "fs" )
49+ await Promise . all (
50+ (
51+ await pathsFor ( kind , profile , jobId )
52+ ) . map (
53+ ( filepath ) =>
54+ new Promise ( ( resolve , reject ) => {
55+ try {
56+ const rs = createReadStream ( filepath )
57+ rs . on ( "close" , resolve )
58+ rs . pipe ( process . stdout )
59+ } catch ( err ) {
60+ reject ( err )
61+ }
62+ } )
63+ )
4864 )
49- )
65+ } else {
66+ const once = async ( ) => {
67+ const tails = await import ( "./dashboard/tailf.js" ) . then ( ( _ ) => _ . default ( kind , profile , jobId , false ) )
68+ await Promise . all ( tails . map ( ( _ ) => _ . then ( ( _ ) => _ . stream . pipe ( process . stdout ) ) ) )
69+ await Promise . all ( tails . map ( ( _ ) => new Promise ( ( resolve ) => _ . then ( ( _ ) => _ . stream . on ( "close" , resolve ) ) ) ) )
70+ return true
71+ }
72+
73+ try {
74+ return once ( )
75+ } catch ( err ) {
76+ await new Promise ( ( resolve ) => setTimeout ( resolve , 2000 ) )
77+ once ( )
78+ }
79+ }
5080
5181 return true
5282}
0 commit comments