@@ -13,24 +13,22 @@ export type ExecOpts = {
1313 cwd : string ;
1414 removeDataFromOutput ?: boolean ;
1515 asJson ?: boolean ;
16+ params ?: { [ key : string ] : string } ;
1617 handlers ?: {
1718 onStdOut ?: ( buffer : string ) => void ;
1819 onStdErr ?: ( buffer : string ) => void ;
1920 } ;
2021} ;
2122
23+ export type ExecProcess = {
24+ cmd : ChildProcess ;
25+ output : Promise < string > ;
26+ args : string [ ] ;
27+ } ;
28+
2229export class CLI {
2330 constructor ( private readonly logger : Logger ) { }
2431
25- public static getInterpolatedArgs (
26- args : string [ ] ,
27- params : { [ key : string ] : string } ,
28- ) {
29- return args . map ( arg =>
30- arg . replace ( / \$ [ \w ] + / , a => params [ a . slice ( 1 ) ] || '' ) ,
31- ) ;
32- }
33-
3432 public static getDataFromStdOut ( output : string ) : string {
3533 return this . stripPrefixFromStdOut (
3634 output
@@ -92,18 +90,32 @@ export class CLI {
9290 . join ( '\n' ) ;
9391 }
9492
95- public exec ( { cmdArgs, cwd, handlers, asJson } : ExecOpts ) : {
96- cmd : ChildProcess ;
97- output : Promise < string > ;
98- } {
99- this . logger . info ( cmdArgs . join ( ' ' ) ) ;
93+ private getInterpolatedArgs (
94+ args : string [ ] ,
95+ params : { [ key : string ] : string } ,
96+ ) {
97+ return args . map ( arg =>
98+ arg . replace ( / \$ [ \w ] + / , a => params [ a . slice ( 1 ) ] || '' ) ,
99+ ) ;
100+ }
101+
102+ public exec ( {
103+ cmdArgs,
104+ cwd,
105+ handlers,
106+ asJson,
107+ params = { } ,
108+ } : ExecOpts ) : ExecProcess {
109+ const interpolatedArgs = this . getInterpolatedArgs ( cmdArgs , params ) ;
110+
111+ this . logger . info ( interpolatedArgs . join ( ' ' ) ) ;
100112
101113 const additionalArgs = [ '--prefix-output' ] ;
102- if ( asJson && ! cmdArgs . includes ( '--json' ) ) {
114+ if ( asJson && ! interpolatedArgs . includes ( '--json' ) ) {
103115 additionalArgs . push ( '--json' ) ;
104116 }
105117
106- const args = cmdArgs . concat ( additionalArgs ) ;
118+ const args = interpolatedArgs . concat ( additionalArgs ) ;
107119
108120 const cmd = spawn ( args [ 0 ] , args . slice ( 1 ) , {
109121 cwd,
@@ -119,6 +131,7 @@ export class CLI {
119131
120132 return {
121133 cmd,
134+ args : interpolatedArgs ,
122135 output : new Promise ( ( res , rej ) => {
123136 cmd . stdout . setEncoding ( 'utf-8' ) ;
124137 cmd . stderr . setEncoding ( 'utf-8' ) ;
0 commit comments