@@ -10,6 +10,7 @@ export interface ILELibrarySettings {
1010
1111export namespace CompileTools {
1212 export const NEWLINE = `\r\n` ;
13+ export const DID_NOT_RUN = - 123 ;
1314
1415 function expandVariables ( variables : Variable ) {
1516 for ( const key in variables ) {
@@ -48,10 +49,15 @@ export namespace CompileTools {
4849 }
4950 }
5051
52+ interface RunCommandEvents {
53+ writeEvent ?: ( content : string ) => void ;
54+ commandConfirm ?: ( command : string ) => Promise < string > ;
55+ }
56+
5157 /**
5258 * Execute a command
5359 */
54- export async function runCommand ( connection : IBMi , options : RemoteCommand , writeEvent ?: ( content : string ) => void ) : Promise < CommandResult > {
60+ export async function runCommand ( connection : IBMi , options : RemoteCommand , events : RunCommandEvents = { } ) : Promise < CommandResult > {
5561 const config = connection . getConfig ( ) ;
5662 if ( config && connection ) {
5763 const cwd = options . cwd ;
@@ -75,26 +81,30 @@ export namespace CompileTools {
7581 variables
7682 ) ;
7783
84+ if ( events . commandConfirm ) {
85+ commandString = await events . commandConfirm ( commandString ) ;
86+ }
87+
7888 if ( commandString ) {
7989 const commands = commandString . split ( `\n` ) . filter ( command => command . trim ( ) . length > 0 ) ;
8090
81- if ( writeEvent ) {
91+ if ( events . writeEvent ) {
8292 if ( options . environment === `ile` && ! options . noLibList ) {
83- writeEvent ( `Current library: ` + ileSetup . currentLibrary + NEWLINE ) ;
84- writeEvent ( `Library list: ` + ileSetup . libraryList . join ( ` ` ) + NEWLINE ) ;
93+ events . writeEvent ( `Current library: ` + ileSetup . currentLibrary + NEWLINE ) ;
94+ events . writeEvent ( `Library list: ` + ileSetup . libraryList . join ( ` ` ) + NEWLINE ) ;
8595 }
8696 if ( options . cwd ) {
87- writeEvent ( `Working directory: ` + options . cwd + NEWLINE ) ;
97+ events . writeEvent ( `Working directory: ` + options . cwd + NEWLINE ) ;
8898 }
89- writeEvent ( `Commands:\n${ commands . map ( command => `\t${ command } \n` ) . join ( `` ) } ` + NEWLINE ) ;
99+ events . writeEvent ( `Commands:\n${ commands . map ( command => `\t${ command } \n` ) . join ( `` ) } ` + NEWLINE ) ;
90100 }
91101
92- const callbacks : StandardIO = writeEvent ? {
102+ const callbacks : StandardIO = events . writeEvent ? {
93103 onStdout : ( data ) => {
94- writeEvent ( data . toString ( ) . replaceAll ( `\n` , NEWLINE ) ) ;
104+ events . writeEvent ! ( data . toString ( ) . replaceAll ( `\n` , NEWLINE ) ) ;
95105 } ,
96106 onStderr : ( data ) => {
97- writeEvent ( data . toString ( ) . replaceAll ( `\n` , NEWLINE ) ) ;
107+ events . writeEvent ! ( data . toString ( ) . replaceAll ( `\n` , NEWLINE ) ) ;
98108 }
99109 } : { } ;
100110
@@ -148,18 +158,19 @@ export namespace CompileTools {
148158
149159 commandResult . command = commandString ;
150160 return commandResult ;
161+
162+ } else {
163+ return {
164+ code : DID_NOT_RUN ,
165+ command : options . command ,
166+ stdout : `` ,
167+ stderr : `Command execution failed. (No command)` ,
168+ } ;
151169 }
152170 }
153171 else {
154172 throw new Error ( "Please connect to an IBM i" ) ;
155173 }
156-
157- return {
158- code : 1 ,
159- command : options . command ,
160- stdout : `` ,
161- stderr : `Command execution failed. (Internal)` ,
162- } ;
163174 }
164175
165176 function buildLibraryList ( config : ILELibrarySettings ) : string [ ] {
0 commit comments