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