本文整理匯總了TypeScript中common/format/exit-code.formatExitCode函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript formatExitCode函數的具體用法?TypeScript formatExitCode怎麽用?TypeScript formatExitCode使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了formatExitCode函數的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: function
spawn.getOutput = async function(opts: SpawnOpts): Promise<string> {
const { code, err, out } = await spawn.exec(opts);
const { command } = opts;
if (code !== 0) {
spawnLogger.info(`${command} failed:\n${err}`);
throw new Error(`${command} failed with code ${formatExitCode(code)}`);
}
return out.trim();
};
示例2: assertPresence
export async function assertPresence(
ctx: Context,
command: string,
args: string[],
parser: RegExp,
extraOpts = {} as any
): Promise<AssertPresenceResult> {
let stdout = "";
let stderr = "";
args = args || [];
const spawnOpts = {
command,
args,
onToken: (tok: string) => {
stdout += "\n" + tok;
},
onErrToken: (tok: string) => {
stderr += "\n" + tok;
},
opts: extraOpts,
logger: new RecordingLogger(mainLogger, "assert-presence"),
ctx,
};
const code = await spawn(spawnOpts);
if (code !== 0) {
throw new Error(
`${command} exited with code ${formatExitCode(
code
)}\n${stdout}\n${stderr}`
);
}
let parsed: string = null;
if (parser) {
let matches = parser.exec(stdout + "\n" + stderr);
if (matches) {
parsed = matches[1];
}
}
return { code, stdout, stderr, parsed };
}