Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
quarto-dev
GitHub Repository: quarto-dev/quarto-cli
Path: blob/main/src/command/update/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 } from "../../tools/tools.ts";
18
import { resolveCompatibleArgs } from "../remove/cmd.ts";
19
20
export const updateCommand = new Command()
21
.name("update")
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
.description(
32
`Updates an extension or global dependency (${installableToolNames().join(", ")}).`,
33
)
34
.example(
35
"Update extension (Github)",
36
"quarto update extension <gh-org>/<gh-repo>",
37
)
38
.example(
39
"Update extension (file)",
40
"quarto update extension <path-to-zip>",
41
)
42
.example(
43
"Update extension (url)",
44
"quarto update extension <url>",
45
)
46
.example(
47
"Update TinyTeX",
48
"quarto update tool tinytex",
49
)
50
.example(
51
"Update Chrome Headless Shell",
52
"quarto update tool chrome-headless-shell",
53
)
54
.example(
55
"Update Chromium (legacy)",
56
"quarto update tool chromium",
57
)
58
.example(
59
"Choose tool to update",
60
"quarto update tool",
61
)
62
.action(
63
async (
64
options: { prompt?: boolean; embed?: string },
65
...target: string[]
66
) => {
67
await initYamlIntelligenceResourcesFromFilesystem();
68
const temp = createTempContext();
69
try {
70
const resolved = resolveCompatibleArgs(target, "extension");
71
72
if (resolved.action === "extension") {
73
// Install an extension
74
if (resolved.name) {
75
await installExtension(
76
resolved.name,
77
temp,
78
options.prompt !== false,
79
options.embed,
80
);
81
} else {
82
info("Please provide an extension name, url, or path.");
83
}
84
} else if (resolved.action === "tool") {
85
// Install a tool
86
if (resolved.name) {
87
// Use the tool name
88
await updateOrInstallTool(resolved.name, "update", options.prompt);
89
} else {
90
// Not provided, give the user a list to choose from
91
const allTools = await loadTools();
92
if (allTools.filter((tool) => !tool.installed).length === 0) {
93
info("All tools are already installed.");
94
} else {
95
// Select which tool should be installed
96
const toolTarget = await selectTool(allTools, "update");
97
if (toolTarget) {
98
info("");
99
await updateOrInstallTool(toolTarget, "update");
100
}
101
}
102
}
103
} else {
104
// This is an unrecognized type option
105
info(
106
`Unrecognized option '${resolved.action}' - please choose 'tool' or 'extension'.`,
107
);
108
}
109
} finally {
110
temp.cleanup();
111
}
112
},
113
);
114
115