import { exec , getBoolInput , which } from "azure-pipelines-task-lib" ; import { addRustToolToPath } from "./path" ; type Command = { tool : string ; name : string ; args : string [ ] ; } ; type InputCommand = { tool : string ; input : string ; args : string [ ] ; } ; const executeCommand = async ( command , resultMessage = "Task done!" ) : Promise < string > => { addRustToolToPath ( ) ; const toolArgs = getToolArgs ( command ) ; return which ( "cargo" ) ? ( await exec ( command . tool , toolArgs ) ) > 0 ? Promise . reject ( new Error ( "An error has occured." ) ) : Promise . resolve ( resultMessage ) : Promise . reject ( new Error ( "Rust toolchains are not available." ) ) ; } ; const getToolArgs = ( command ) : string => { const fullCommand = isInputCommand ( command ) ? [ ... command . args , command . input ] : [ command . name , ... command . args ] ; return fullCommand . filter ( p => p !== null && ! p . includes ( "null" ) ) . reduce ( ( p , n ) => `${ p } ${ n }` ) . trim ( ) ; } ; const isInputCommand = ( command ) : command is InputCommand => { return command . input !== undefined ; } ; const createCommand = ( tool , name , options ) : Command => { return { args : ! ! options ? options . split ( " " ) : [ ] , name , tool } ; } ; const createInputCommand = ( tool , input , options ) : InputCommand => { return { args : ! ! options ? options . split ( " " ) : [ ] , input , tool } ; } ; export { Command , executeCommand , createCommand , createInputCommand } ;