Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
quarto-dev
GitHub Repository: quarto-dev/quarto-cli
Path: blob/main/package/src/util/cmd.ts
6450 views
1
/*
2
* cmd.ts
3
*
4
* Copyright (C) 2020-2022 Posit Software, PBC
5
*
6
*/
7
8
import { debug, error, info } from "../../../src/deno_ral/log.ts";
9
10
export interface CmdResult {
11
status: Deno.CommandStatus;
12
stdout: string;
13
stderr: string;
14
}
15
16
export async function runCmd(
17
runCmd: string,
18
args: string[],
19
): Promise<CmdResult> {
20
// const cmd: string[] = [];
21
// cmd.push(runCmd);
22
// cmd.push(...args);
23
24
info([runCmd, ...args]);
25
info(`Starting ${runCmd}`);
26
const cmd = new Deno.Command(runCmd, {
27
args,
28
stdout: "piped",
29
stderr: "piped",
30
});
31
const output = await cmd.output();
32
const stdout = new TextDecoder().decode(output.stdout);
33
const stderr = new TextDecoder().decode(output.stderr);
34
info(`Finished ${runCmd}`);
35
debug(stdout);
36
37
const code = output.code;
38
info(`Status ${code}`);
39
if (code !== 0) {
40
error(stderr);
41
throw Error(`Command ${[runCmd, ...args]} failed.`);
42
}
43
44
return {
45
status: output,
46
stdout,
47
stderr,
48
};
49
}
50
51