Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
quarto-dev
GitHub Repository: quarto-dev/quarto-cli
Path: blob/main/src/command/run/run.ts
3583 views
1
/*
2
* run.ts
3
*
4
* Copyright (C) 2020-2022 Posit Software, PBC
5
*/
6
7
import { Command } from "cliffy/command/command.ts";
8
9
import { existsSync } from "../../deno_ral/fs.ts";
10
import { error } from "../../deno_ral/log.ts";
11
import { handlerForScript } from "../../core/run/run.ts";
12
import { exitWithCleanup } from "../../core/cleanup.ts";
13
14
export async function runScript(args: string[], env?: Record<string, string>) {
15
const script = args[0];
16
if (!script) {
17
error("quarto run: no script specified");
18
exitWithCleanup(1);
19
throw new Error(); // unreachable
20
}
21
if (!existsSync(script)) {
22
error("quarto run: script '" + script + "' not found");
23
exitWithCleanup(1);
24
throw new Error(); // unreachable
25
}
26
const handler = await handlerForScript(script);
27
if (!handler) {
28
error("quarto run: no handler found for script '" + script + "'");
29
exitWithCleanup(1);
30
throw new Error(); // unreachable
31
}
32
return await handler.run(script, args.slice(1), undefined, { env });
33
}
34
35
// run 'command' (this is a fake command that is here just for docs,
36
// the actual processing of 'run' bypasses cliffy entirely)
37
export const runCommand = new Command()
38
.name("run")
39
.stopEarly()
40
.arguments("[script:string] [...args]")
41
.description(
42
"Run a TypeScript, R, Python, or Lua script.\n\n" +
43
"Run a utility script written in a variety of languages. For details, see:\n" +
44
"https://quarto.org/docs/projects/scripts.html#periodic-scripts",
45
);
46
47