improve silent options

This commit is contained in:
Philipp Kunz 2017-06-27 11:18:37 +02:00
parent bc2d0dda3f
commit ca175205ee
3 changed files with 30 additions and 11 deletions

View File

@ -27,7 +27,11 @@ export declare let execSilent: (commandStringArg: string) => Promise<IExecResult
/** /**
* executes a command and allws you to stream output * executes a command and allws you to stream output
*/ */
export declare let execStreaming: (commandStringArg: string) => { export declare let execStreaming: (commandStringArg: string, silentArg?: boolean) => {
childProcess: ChildProcess;
finalPromise: Promise<IExecResult>;
};
export declare let execStreamingSilent: (commandStringArg: string) => {
childProcess: ChildProcess; childProcess: ChildProcess;
finalPromise: Promise<IExecResult>; finalPromise: Promise<IExecResult>;
}; };
@ -36,7 +40,8 @@ export declare let execStreaming: (commandStringArg: string) => {
* @param commandStringArg * @param commandStringArg
* @param regexArg * @param regexArg
*/ */
export declare let execAndWaitForLine: (commandStringArg: string, regexArg: RegExp) => Promise<{}>; export declare let execAndWaitForLine: (commandStringArg: string, regexArg: RegExp, silentArg?: boolean) => Promise<{}>;
export declare let execAndWaitForLineSilent: (commandStringArg: string, regexArg: RegExp) => void;
/** /**
* get a path * get a path
*/ */

View File

@ -32,9 +32,9 @@ exports.execSilent = (commandStringArg) => {
/** /**
* executes a command and allws you to stream output * executes a command and allws you to stream output
*/ */
exports.execStreaming = (commandStringArg) => { exports.execStreaming = (commandStringArg, silentArg = false) => {
let childProcessEnded = plugins.smartq.defer(); let childProcessEnded = plugins.smartq.defer();
let execChildProcess = plugins.shelljs.exec(commandStringArg, { async: true, silent: true }, (code, stdout, stderr) => { let execChildProcess = plugins.shelljs.exec(commandStringArg, { async: true, silent: silentArg }, (code, stdout, stderr) => {
childProcessEnded.resolve({ childProcessEnded.resolve({
exitCode: code, exitCode: code,
stdout: stdout stdout: stdout
@ -45,14 +45,17 @@ exports.execStreaming = (commandStringArg) => {
finalPromise: childProcessEnded.promise finalPromise: childProcessEnded.promise
}; };
}; };
exports.execStreamingSilent = (commandStringArg) => {
return exports.execStreaming(commandStringArg, true);
};
/** /**
* executes a command and returns promise that will be fullfilled once an putput line matches RegexArg * executes a command and returns promise that will be fullfilled once an putput line matches RegexArg
* @param commandStringArg * @param commandStringArg
* @param regexArg * @param regexArg
*/ */
exports.execAndWaitForLine = (commandStringArg, regexArg) => { exports.execAndWaitForLine = (commandStringArg, regexArg, silentArg = false) => {
let done = plugins.smartq.defer(); let done = plugins.smartq.defer();
let execStreamingResult = exports.execStreaming(commandStringArg); let execStreamingResult = exports.execStreaming(commandStringArg, silentArg);
execStreamingResult.childProcess.stdout.on('data', (stdOutChunk) => { execStreamingResult.childProcess.stdout.on('data', (stdOutChunk) => {
if (regexArg.test(stdOutChunk)) { if (regexArg.test(stdOutChunk)) {
done.resolve(); done.resolve();
@ -60,6 +63,9 @@ exports.execAndWaitForLine = (commandStringArg, regexArg) => {
}); });
return done.promise; return done.promise;
}; };
exports.execAndWaitForLineSilent = (commandStringArg, regexArg) => {
exports.execAndWaitForLine(commandStringArg, regexArg, true);
};
/** /**
* get a path * get a path
*/ */
@ -73,4 +79,4 @@ exports.which = (cmd) => {
}); });
return done.promise; return done.promise;
}; };
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzaGVsbC53cmFwLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRzaGVsbC53cmFwLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBQUEsZ0RBQStDO0FBc0IvQzs7O0dBR0c7QUFDUSxRQUFBLElBQUksR0FBRyxDQUFDLGdCQUF3QjtJQUN6QyxJQUFJLElBQUksR0FBRyxPQUFPLENBQUMsTUFBTSxDQUFDLEtBQUssRUFBZSxDQUFBO0lBQzlDLE9BQU8sQ0FBQyxPQUFPLENBQUMsSUFBSSxDQUFDLGdCQUFnQixFQUFFLEVBQUUsS0FBSyxFQUFFLElBQUksRUFBRSxFQUFFLENBQUMsSUFBSSxFQUFFLE1BQU0sRUFBRSxNQUF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BQUcsRUFBRSxJQUFZO1FBQ25DLEVBQUUsQ0FBQyxDQUFDLEdBQUcsQ0FBQyxDQUFDLENBQUM7WUFDUixJQUFJLENBQUMsTUFBTSxDQUFDLEdBQUcsQ0FBQyxDQUFBO1FBQ2xCLENBQUM7UUFDRCxJQUFJLENBQUMsT0FBTyxDQUFDLElBQUksQ0FBQyxDQUFBO0lBQ3BCLENBQUMsQ0FBQyxDQUFBO0lBQ0YsTUFBTSxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUE7QUFDckIsQ0FBQyxDQUFBIn0=

View File

@ -53,9 +53,9 @@ export let execSilent = (commandStringArg: string) => {
/** /**
* executes a command and allws you to stream output * executes a command and allws you to stream output
*/ */
export let execStreaming = (commandStringArg: string) => { export let execStreaming = (commandStringArg: string, silentArg: boolean = false) => {
let childProcessEnded = plugins.smartq.defer<IExecResult>() let childProcessEnded = plugins.smartq.defer<IExecResult>()
let execChildProcess = plugins.shelljs.exec(commandStringArg, {async: true, silent: true}, (code, stdout, stderr) => { let execChildProcess = plugins.shelljs.exec(commandStringArg, {async: true, silent: silentArg}, (code, stdout, stderr) => {
childProcessEnded.resolve({ childProcessEnded.resolve({
exitCode: code, exitCode: code,
stdout: stdout stdout: stdout
@ -67,14 +67,18 @@ export let execStreaming = (commandStringArg: string) => {
} }
} }
export let execStreamingSilent = (commandStringArg: string) => {
return execStreaming(commandStringArg, true)
}
/** /**
* executes a command and returns promise that will be fullfilled once an putput line matches RegexArg * executes a command and returns promise that will be fullfilled once an putput line matches RegexArg
* @param commandStringArg * @param commandStringArg
* @param regexArg * @param regexArg
*/ */
export let execAndWaitForLine = (commandStringArg: string, regexArg: RegExp) => { export let execAndWaitForLine = (commandStringArg: string, regexArg: RegExp, silentArg: boolean = false) => {
let done = plugins.smartq.defer() let done = plugins.smartq.defer()
let execStreamingResult = execStreaming(commandStringArg) let execStreamingResult = execStreaming(commandStringArg, silentArg)
execStreamingResult.childProcess.stdout.on('data', (stdOutChunk: string) => { execStreamingResult.childProcess.stdout.on('data', (stdOutChunk: string) => {
if (regexArg.test(stdOutChunk)) { if (regexArg.test(stdOutChunk)) {
done.resolve() done.resolve()
@ -83,6 +87,10 @@ export let execAndWaitForLine = (commandStringArg: string, regexArg: RegExp) =>
return done.promise return done.promise
} }
export let execAndWaitForLineSilent = (commandStringArg: string, regexArg: RegExp) => {
execAndWaitForLine(commandStringArg, regexArg, true)
}
/** /**
* get a path * get a path
*/ */