Add exec (#10)

* Add exec

* Fix linux tests

* unnecessary dependency

* Dont prefix ExecOptions with I

* Consistency nits

* Respond to feedback

* Add toolrunner explanatory quote

* Format
This commit is contained in:
Danny McCormick
2019-05-28 15:21:45 -04:00
committed by GitHub
parent 8ebbf59cb3
commit c5f27c3c1b
13 changed files with 1609 additions and 0 deletions
+28
View File
@@ -0,0 +1,28 @@
import * as im from './interfaces'
import * as tr from './toolrunner'
/**
* Exec a command.
* Output will be streamed to the live console.
* Returns promise with return code
*
* @param commandLine command to execute (can include additional args). Must be correctly escaped.
* @param args optional arguments for tool. Escaping is handled by the lib.
* @param options optional exec options. See ExecOptions
* @returns Promise<number> exit code
*/
export async function exec(
commandLine: string,
args?: string[],
options?: im.ExecOptions
): Promise<number> {
const commandArgs = tr.argStringToArray(commandLine)
if (commandArgs.length === 0) {
throw new Error(`Parameter 'commandLine' cannot be null or empty.`)
}
// Path to tool to execute should be first arg
const toolPath = commandArgs[0]
args = commandArgs.slice(1).concat(args || [])
const runner: tr.ToolRunner = new tr.ToolRunner(toolPath, args, options)
return runner.exec()
}