Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
quarto-dev
GitHub Repository: quarto-dev/quarto-cli
Path: blob/main/src/command/install/cmd.ts
3584 views
1
/*
2
* cmd.ts
3
*
4
* Copyright (C) 2021-2022 Posit Software, PBC
5
*/
6
import { Command } from "cliffy/command/mod.ts";
7
import { initYamlIntelligenceResourcesFromFilesystem } from "../../core/schema/utils.ts";
8
import { createTempContext } from "../../core/temp.ts";
9
import { installExtension } from "../../extension/install.ts";
10
11
import { info } from "../../deno_ral/log.ts";
12
import {
13
loadTools,
14
selectTool,
15
updateOrInstallTool,
16
} from "../../tools/tools-console.ts";
17
import { installTool } from "../../tools/tools.ts";
18
import { resolveCompatibleArgs } from "../remove/cmd.ts";
19
20
export const installCommand = new Command()
21
.name("install")
22
.arguments("[target...]")
23
.option(
24
"--no-prompt",
25
"Do not prompt to confirm actions",
26
)
27
.option(
28
"--embed <extensionId>",
29
"Embed this extension within another extension (used when authoring extensions).",
30
{
31
hidden: true,
32
},
33
)
34
.option(
35
"--update-path",
36
"Update system path when a tool is installed",
37
)
38
.description(
39
"Installs a global dependency (TinyTex or Chromium).",
40
)
41
.example(
42
"Install TinyTeX",
43
"quarto install tinytex",
44
)
45
.example(
46
"Install Chromium",
47
"quarto install chromium",
48
)
49
.example(
50
"Choose tool to install",
51
"quarto install",
52
)
53
.action(
54
async (
55
options: { prompt?: boolean; embed?: string; updatePath?: boolean },
56
...target: string[]
57
) => {
58
await initYamlIntelligenceResourcesFromFilesystem();
59
const temp = createTempContext();
60
61
const resolved = resolveCompatibleArgs(target || [], "tool");
62
63
try {
64
if (resolved.action === "extension") {
65
// Install an extension
66
if (resolved.name) {
67
await installExtension(
68
resolved.name,
69
temp,
70
options.prompt !== false,
71
options.embed,
72
);
73
} else {
74
info("Please provide an extension name, url, or path.");
75
}
76
} else if (resolved.action === "tool") {
77
// Install a tool
78
if (resolved.name) {
79
// Use the tool name
80
await updateOrInstallTool(
81
resolved.name,
82
"install",
83
options.prompt,
84
options.updatePath,
85
);
86
} else {
87
// Not provided, give the user a list to choose from
88
const allTools = await loadTools();
89
if (allTools.filter((tool) => !tool.installed).length === 0) {
90
info("All tools are already installed.");
91
} else {
92
// Select which tool should be installed
93
const toolTarget = await selectTool(allTools, "install");
94
if (toolTarget) {
95
info("");
96
await installTool(toolTarget, options.updatePath);
97
}
98
}
99
}
100
} else {
101
// This is an unrecognized type option
102
info(
103
`Unrecognized option '${resolved.action}' - please choose 'tool' or 'extension'.`,
104
);
105
}
106
} finally {
107
temp.cleanup();
108
}
109
},
110
);
111
112