Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
quarto-dev
GitHub Repository: quarto-dev/quarto-cli
Path: blob/main/src/command/dev-call/cmd.ts
6433 views
1
import { Command } from "cliffy/command/mod.ts";
2
import { quartoConfig } from "../../core/quarto.ts";
3
import { commands } from "../command.ts";
4
import { buildJsCommand } from "./build-artifacts/cmd.ts";
5
import { validateYamlCommand } from "./validate-yaml/cmd.ts";
6
import { showAstTraceCommand } from "./show-ast-trace/cmd.ts";
7
import { makeAstDiagramCommand } from "./make-ast-diagram/cmd.ts";
8
import { pullGitSubtreeCommand } from "./pull-git-subtree/cmd.ts";
9
import { typstGatherCommand } from "./typst-gather/cmd.ts";
10
11
type CommandOptionInfo = {
12
name: string;
13
description: string;
14
args: [];
15
flags: string[];
16
equalsSign: boolean;
17
typeDefinition: string;
18
};
19
20
type CommandInfo = {
21
hidden: boolean;
22
name: string;
23
description: string;
24
options: CommandOptionInfo[];
25
// arguments: string[];
26
// subcommands: CommandInfo[];
27
// aliases: string[];
28
examples: { name: string; description: string }[];
29
// flags: string[];
30
usage: string;
31
commands: CommandInfo[];
32
};
33
34
const generateCliInfoCommand = new Command()
35
.name("cli-info")
36
.description("Generate JSON information about the Quarto CLI.")
37
.action(async () => {
38
const output: Record<string, unknown> = {};
39
output["version"] = quartoConfig.version();
40
const commandsInfo: CommandInfo[] = [];
41
output["commands"] = commandsInfo;
42
43
// Cliffy doesn't export the "hidden" property, so we maintain our own list
44
// here
45
const hiddenCommands = [
46
"dev-call",
47
"editor-support",
48
"create-project",
49
];
50
// deno-lint-ignore no-explicit-any
51
const cmdAsJson = (cmd: any): CommandInfo => {
52
return {
53
name: cmd.getName(),
54
hidden: hiddenCommands.includes(cmd.getName()),
55
description: cmd.getDescription(),
56
options: cmd.getOptions(),
57
usage: cmd.getUsage(),
58
examples: cmd.getExamples(),
59
commands: cmd.getCommands().map(cmdAsJson),
60
};
61
};
62
output["commands"] = commands().map(cmdAsJson);
63
console.log(JSON.stringify(output, null, 2));
64
});
65
66
export const devCallCommand = new Command()
67
.name("dev-call")
68
.hidden()
69
.description(
70
"Access internals of Quarto - this command is not intended for general use.",
71
)
72
.action(() => {
73
devCallCommand.showHelp();
74
Deno.exit(1);
75
})
76
.command("cli-info", generateCliInfoCommand)
77
.command("validate-yaml", validateYamlCommand)
78
.command("build-artifacts", buildJsCommand)
79
.command("show-ast-trace", showAstTraceCommand)
80
.command("make-ast-diagram", makeAstDiagramCommand)
81
.command("pull-git-subtree", pullGitSubtreeCommand)
82
.command("typst-gather", typstGatherCommand);
83
84