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
12925 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 { installableToolNames, 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 (${installableToolNames().join(", ")}).`,
40
)
41
.example(
42
"Install TinyTeX",
43
"quarto install tinytex",
44
)
45
.example(
46
"Install Chrome Headless Shell",
47
"quarto install chrome-headless-shell",
48
)
49
.example(
50
"Install Chromium (legacy)",
51
"quarto install chromium",
52
)
53
.example(
54
"Choose tool to install",
55
"quarto install",
56
)
57
.action(
58
async (
59
options: { prompt?: boolean; embed?: string; updatePath?: boolean },
60
...target: string[]
61
) => {
62
await initYamlIntelligenceResourcesFromFilesystem();
63
const temp = createTempContext();
64
65
const resolved = resolveCompatibleArgs(target || [], "tool");
66
67
try {
68
if (resolved.action === "extension") {
69
// Install an extension
70
if (resolved.name) {
71
await installExtension(
72
resolved.name,
73
temp,
74
options.prompt !== false,
75
options.embed,
76
);
77
} else {
78
info("Please provide an extension name, url, or path.");
79
}
80
} else if (resolved.action === "tool") {
81
// Install a tool
82
if (resolved.name) {
83
// Use the tool name
84
await updateOrInstallTool(
85
resolved.name,
86
"install",
87
options.prompt,
88
options.updatePath,
89
);
90
} else {
91
// Not provided, give the user a list to choose from
92
const allTools = await loadTools();
93
if (allTools.filter((tool) => !tool.installed).length === 0) {
94
info("All tools are already installed.");
95
} else {
96
// Select which tool should be installed
97
const toolTarget = await selectTool(allTools, "install");
98
if (toolTarget) {
99
info("");
100
await installTool(toolTarget, options.updatePath);
101
}
102
}
103
}
104
} else {
105
// This is an unrecognized type option
106
info(
107
`Unrecognized option '${resolved.action}' - please choose 'tool' or 'extension'.`,
108
);
109
}
110
} finally {
111
temp.cleanup();
112
}
113
},
114
);
115
116