@@ -91,6 +91,18 @@ export interface PodStatus {
91
91
reason ?: string ;
92
92
}
93
93
94
+ export interface ExecOptions {
95
+ log ?: boolean ;
96
+ silent ?: boolean ;
97
+ ignoreError ?: boolean ;
98
+ }
99
+
100
+ const defaultExecOptions : ExecOptions = {
101
+ log : true ,
102
+ silent : false ,
103
+ ignoreError : true ,
104
+ }
105
+
94
106
export const formatChainID = ( input : string ) : string => {
95
107
// Replace underscores with hyphens
96
108
let formattedName = input . replace ( / _ / g, '-' ) ;
@@ -122,11 +134,20 @@ export class StarshipClient implements StarshipClientI {
122
134
this . version = readAndParsePackageJson ( ) . version ;
123
135
}
124
136
125
- private exec ( cmd : string [ ] , log : boolean = true , silent : boolean = false ) : shell . ShellString {
137
+ private exec ( cmd : string [ ] , options : Partial < ExecOptions > = { } ) : shell . ShellString {
138
+ const opts = { ...defaultExecOptions , ...options } ;
126
139
this . checkDependencies ( ) ;
127
140
const str = cmd . join ( ' ' ) ;
128
- if ( log ) this . log ( str ) ;
129
- return shell . exec ( str , { silent } ) ;
141
+ if ( opts . log ) this . log ( str ) ;
142
+
143
+ const result = shell . exec ( str , { silent : opts . silent } ) ;
144
+
145
+ if ( result . code !== 0 && ! opts . ignoreError ) {
146
+ this . log ( chalk . red ( 'Error: ' ) + result . stderr ) ;
147
+ this . exit ( result . code ) ;
148
+ }
149
+
150
+ return result ;
130
151
}
131
152
132
153
private log ( str : string ) : void {
@@ -311,16 +332,16 @@ export class StarshipClient implements StarshipClientI {
311
332
'add' ,
312
333
this . ctx . repo ,
313
334
this . ctx . repoUrl
314
- ] ) ;
315
- this . exec ( [ 'helm' , 'repo' , 'update' ] ) ;
335
+ ] , { ignoreError : false } ) ;
336
+ this . exec ( [ 'helm' , 'repo' , 'update' ] , { ignoreError : false } ) ;
316
337
this . exec ( [
317
338
'helm' ,
318
339
'search' ,
319
340
'repo' ,
320
341
this . ctx . chart ,
321
342
'--version' ,
322
343
this . config . version
323
- ] ) ;
344
+ ] , { ignoreError : false } ) ;
324
345
}
325
346
326
347
private ensureFileExists ( filename : string ) : void {
@@ -363,7 +384,7 @@ export class StarshipClient implements StarshipClientI {
363
384
}
364
385
} ) ;
365
386
366
- this . exec ( cmd ) ;
387
+ this . exec ( cmd , { ignoreError : false } ) ;
367
388
this . log ( "Run \"starship get-pods\" to check the status of the cluster" ) ;
368
389
}
369
390
@@ -386,7 +407,7 @@ export class StarshipClient implements StarshipClientI {
386
407
}
387
408
388
409
public checkConnection ( ) : void {
389
- const result = this . exec ( [ 'kubectl' , 'get' , 'nodes' ] , false , true ) ;
410
+ const result = this . exec ( [ 'kubectl' , 'get' , 'nodes' ] , { log : false , silent : true } ) ;
390
411
391
412
if ( result . code !== 0 ) {
392
413
this . log ( chalk . red ( 'Error: Unable to connect to the Kubernetes cluster.' ) ) ;
@@ -406,7 +427,7 @@ export class StarshipClient implements StarshipClientI {
406
427
'-o' ,
407
428
'custom-columns=:metadata.name' ,
408
429
...this . getArgs ( ) ,
409
- ] , false , true )
430
+ ] , { log : false , silent : true } )
410
431
411
432
// Split the output by new lines and filter out any empty lines
412
433
const podNames = result . split ( '\n' ) . filter ( name => name . trim ( ) !== '' ) ;
@@ -434,7 +455,7 @@ export class StarshipClient implements StarshipClientI {
434
455
'-o' ,
435
456
'custom-columns=:status.phase,:status.containerStatuses[*].ready,:status.containerStatuses[*].restartCount,:status.containerStatuses[*].state.waiting.reason' ,
436
457
...this . getArgs ( ) ,
437
- ] , false , true ) . trim ( ) ;
458
+ ] , { log : false , silent : true } ) . trim ( ) ;
438
459
439
460
const [ phase , readyList , restartCountList , reason ] = result . split ( / \s + / ) ;
440
461
const ready = readyList . split ( ',' ) . every ( state => state === 'true' ) ;
0 commit comments