-
Notifications
You must be signed in to change notification settings - Fork 432
Expand file tree
/
Copy pathcmd.ts
More file actions
74 lines (69 loc) · 2.12 KB
/
cmd.ts
File metadata and controls
74 lines (69 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import { Command } from "cliffy/command/mod.ts";
import { quartoConfig } from "../../core/quarto.ts";
import { commands } from "../command.ts";
import { buildJsCommand } from "./build-artifacts/cmd.ts";
import { validateYamlCommand } from "./validate-yaml/cmd.ts";
type CommandOptionInfo = {
name: string;
description: string;
args: [];
flags: string[];
equalsSign: boolean;
typeDefinition: string;
};
type CommandInfo = {
hidden: boolean;
name: string;
description: string;
options: CommandOptionInfo[];
// arguments: string[];
// subcommands: CommandInfo[];
// aliases: string[];
examples: { name: string; description: string }[];
// flags: string[];
usage: string;
commands: CommandInfo[];
};
const generateCliInfoCommand = new Command()
.name("cli-info")
.description("Generate JSON information about the Quarto CLI.")
.action(async () => {
const output: Record<string, unknown> = {};
output["version"] = quartoConfig.version();
const commandsInfo: CommandInfo[] = [];
output["commands"] = commandsInfo;
// Cliffy doesn't export the "hidden" property, so we maintain our own list
// here
const hiddenCommands = [
"dev-call",
"editor-support",
"create-project",
];
// deno-lint-ignore no-explicit-any
const cmdAsJson = (cmd: any): CommandInfo => {
return {
name: cmd.getName(),
hidden: hiddenCommands.includes(cmd.getName()),
description: cmd.getDescription(),
options: cmd.getOptions(),
usage: cmd.getUsage(),
examples: cmd.getExamples(),
commands: cmd.getCommands().map(cmdAsJson),
};
};
output["commands"] = commands().map(cmdAsJson);
console.log(JSON.stringify(output, null, 2));
});
export const devCallCommand = new Command()
.name("dev-call")
.hidden()
.description(
"Access internals of Quarto - this command is not intended for general use.",
)
.action(() => {
devCallCommand.showHelp();
Deno.exit(1);
})
.command("cli-info", generateCliInfoCommand)
.command("validate-yaml", validateYamlCommand)
.command("build-artifacts", buildJsCommand);