This commit is contained in:
2017-03-07 18:07:03 +01:00
parent 5ede124f56
commit d9b8eb3bf0
7 changed files with 223 additions and 247 deletions

View File

@@ -19,7 +19,8 @@ checkNvm()
* @param commandArg - The command to execute
* @param retryArg - The retryArg: 0 to any positive number will retry, -1 will always succeed, -2 will return undefined
*/
export let bash = (commandArg: string, retryArg: number = 2, bareArg: boolean = false): string => {
export let bash = (commandArg: string, retryArg: number = 2, bareArg: boolean = false): Promise<string> => {
let done = plugins.q.defer<string>()
let exitCode: number
let stdOut: string
let execResult
@@ -43,6 +44,7 @@ export let bash = (commandArg: string, retryArg: number = 2, bareArg: boolean =
// determine how bash reacts to error and success
if (exitCode !== 0 && i === retryArg) { // something went wrong and retries are exhausted
if (failOnError) {
plugins.beautylog.error('something went wrong and retries are exhausted')
process.exit(1)
}
} else if (exitCode === 0) { // everything went fine, or no error wanted
@@ -55,19 +57,19 @@ export let bash = (commandArg: string, retryArg: number = 2, bareArg: boolean =
} else {
plugins.beautylog.log('ShellExec would be: ' + commandArg)
}
return stdOut
return done.promise
}
/**
* bashBare allows usage of bash without sourcing any files like nvm
*/
export let bashBare = (commandArg: string, retryArg: number = 2) => {
export let bashBare = (commandArg: string, retryArg: number = 2): Promise<string> => {
return bash(commandArg, retryArg, true)
}
/**
* bashNoError allows executing stuff without throwing an error
*/
export let bashNoError = (commandArg: string): string => {
export let bashNoError = (commandArg: string): Promise<string> => {
return bash(commandArg, -1)
}